Giter Site home page Giter Site logo

Comments (5)

cbeck88 avatar cbeck88 commented on August 27, 2024

Good catch, this appears to be an oversight.

I don't understand why set and map have diverged in this regard:

https://github.com/serge-sans-paille/frozen/blob/master/include/frozen/set.h#L34

template <class Key, std::size_t N, class Compare = std::less<Key>> class set {
  using container_type = bits::carray<Key, N>;
  Compare const compare_;
  container_type const keys_;

and this is the only specialization, while in frozen::map it is different, and we have a specialization for N=0 case:

template <class Key, class Value, std::size_t N, class Compare = std::less<Key>>
class map {
  using container_type = bits::carray<std::pair<Key, Value>, N>;
  impl::CompareKey<Compare> compare_;
  container_type items_;

...

template <class Key, class Value, class Compare>
class map<Key, Value, 0, Compare> {
  using container_type =
      bits::carray<std::pair<Key, Value>, 1>; // just for the type definitions
  impl::CompareKey<Compare> compare_;

There are a few things that we must do IMO:
1.) Make a specialization in bits::carray for the case of N=0 that prevents a size zero array from happening. This will silence the warning reported in the tickets
2.) The code for case map with N=0 is wrong to use 1 when N=0. I understand that the goal is to avoid forming a zero length C-array when N=0. The existing code is defective because if Key or Value is not default constructible, then empty map won't compile. It should be bits::carray<std::pair<Key, Value>, 0>, and if we will use bits::carray here then bits::carray should be required to work even when N=0 and work around the C-array length zero issue, just as std::array does... I have already done that in our corporate (internal) copy of frozen.
3.) We should patch make_map as follows to avoid creating length zero arrays. I have already done this in our corporate (internal) copy of frozen, I didn't have time to make a PR upstream:

template <typename T, typename U, std::size_t N>
constexpr auto make_map(std::pair<T, U> const (&items)[N])
{
    return map<T, U, N>{bits::to_array(items)};
}

// This overload is provided so that `make_map({})` will compile and produce an array of size 0
struct ignored_tag
{
};

template <typename T, typename U>
constexpr auto make_map(ignored_tag)
{
    return map<T, U, 0>();
}

Ideally we would also have a test that exercises make_map<..., ...>({}) and checks that there are no warnings.

from frozen.

serge-sans-paille avatar serge-sans-paille commented on August 27, 2024

@cbeck : as an alternative, specializing carray to gracefully handle the N = 0 case seems less intrusive to me. i'm experiencing with that and we can discuss the implementation!

from frozen.

serge-sans-paille avatar serge-sans-paille commented on August 27, 2024

ok, that was your point 1). Silly me :-)

from frozen.

cbeck avatar cbeck commented on August 27, 2024

You meant @cbeck88.

from frozen.

serge-sans-paille avatar serge-sans-paille commented on August 27, 2024

definitely :-) sorry for the noise.

from frozen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.