with zero runtime overhead and O(1) compile-time complexity(measured by template instantiation) on g++-6+ and clang-3.6+ with flag -std=c++14 and -O3. It is also experimented that zero runtime and O(1) compile-time complexity could be achieved on constant path of g++-5. In the next few days, I'm going to focus on MSVC2017 efficient implementation.
The list should know I've been impressed with what candidate students have sent me to prove their programming competency. It makes me feel old and a little past it.
Regarding the design of static_map's interface, I doubt that is it possible or worthwhile to implement a subscript-like operator/function that checks boundary at compile time(given that key is a constant expression)? Compilation errors tend to be more likely to be discovered than runtime exception.
So the list understands: constexpr mapped_type &at(const key_type &key) const { if(key_not_in_map) throw std::out_of_range(); } This works under constexpr, but annoyingly causes the compiler to generate code which throws std::out_of_range() which is a showstopper. What would be much better: constexpr mapped_type &at(const key_type &key) const { static_assert(!key_not_in_map, "key not in map"); } ... but constexpr functions are not necessarily executed at compile time, so we can't do this. I believe C++ 17's if constexpr() would fix this, but having a C++ 14 solution would be nice. Niall -- ned Productions Limited Consulting http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/