Comments (5)
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.
@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.
ok, that was your point 1). Silly me :-)
from frozen.
You meant @cbeck88.
from frozen.
definitely :-) sorry for the noise.
from frozen.
Related Issues (20)
- Allow modification of map values HOT 7
- Add conan package HOT 3
- frozen::unordered_map, fails in MSVC 2017 with C++17 HOT 3
- Hashing with Boost Hash Library HOT 2
- Nested containers with different sizes HOT 5
- frozen::unordered_multiset? HOT 1
- Compilation errors in VS 2019 HOT 7
- include/frozen/map.h:114:12: error: binding reference of type 'int' to value of type 'const int' drops 'const' qualifier HOT 2
- Error when compiling the examples in the released version 1.0.0 HOT 2
- Support for std::array? HOT 2
- Warning concerning a missing constexpr HOT 3
- [Windows][VS][MSVC] Compilation failed - min / max macros HOT 2
- Add map/set final() method? HOT 5
- Status of cvector and carray
- Building tests fail because of incompatible catch2 version. HOT 1
- How to create a string key at runtime? HOT 5
- Frozen bimap? HOT 2
- Frozen constexpr map AVL tree ?
- Test compilation error HOT 5
- F
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from frozen.