static_assert on initializer_list::size()
“Initializer lists” are just horrible kludges. Don’t: #include <initializer_list> template<typename T> void Dont(std::initializer_list<T> list) { // Bad! static_assert(list.size() == 3, “Exactly three elements are required.”); } void Test() { Dont({1,2,3}); } Do: template<typename T, std::size_t N> void Do(const T(&list)[N]) { // Good! static_assert(N == 3, “Exactly three elements are required.”); } void Test() { Do({1,2,3}); … Read more