
Paul Fultz II
I am probably missing something, but can't you check that the first element of every pair going into the map is a compile-time constant. « []
No, because not only compile-time constants can be used as the keys of a Map.
Yes, but as a simple smoke screen, you could always check that the key compared against itself will return an `IntregralConstant`. That should always be required to be valid, and it would help catch errors earlier on.
That's an interesting idea, and I just implemented this for both Set and Map. For illustration, here's what happens when 1. creating a Map with something else than pairs: auto m = make_map(1); error: static_assert failed "hana::make<Map>(pairs...) requires all the 'pairs' to be Products" static_assert(hana::all(are_pairs), ^ ~~~~~~~~~~~~~~~~~~~~ 2. creating a Map with non-Comparable keys: struct Foo { }; auto m = make_map(make_pair(Foo{}, "one")); error: static_assert failed "hana::make<Map>(pairs...) requires all the keys to be Comparable" static_assert(hana::all(are_Comparable), ^ ~~~~~~~~~~~~~~~~~~~~~~~~~ 3. creating a Map with keys that are obviously not Comparable at compile-time auto m = make_map(make_pair(1, "one")); error: static_assert failed "hana::make<Map>(pairs...) requires all the keys to be Comparable at compile-time" static_assert(hana::all(are_compile_time_Comparable), ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Similar error messages are thrown by Set when using non-Comparable or runtime-Comparable keys. Regards, Louis