Louis Dionne
Paul Fultz II
writes: 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
[...]
Actually, I just realized something. While it is documented that Map and Set require compile-time Comparable keys, there are some operations that make sense to perform on Sets and Maps with runtime-Comparable keys. Consider the following: auto xs = make_set(1, 2, 3); auto ys = make_set(1, 3, 2); assert(ys == xs); The funny thing is that this actually works. If you think of it, the code that should be generated is something like: if (xs and ys have different # of elements) return false_; // known at compile-time else return 1 is in ys && 2 is in ys && 3 is in ys; // known at runtime Anyway, since the documentation says Set and Map require compile-time Comparable keys, I'll stick to it for now. However, I might decide to allow runtime keys when I'll focus on improving the associative structures. Regards, Louis