constexpr-ness of std::initializer_list::size() vs std::array::size()
问题 The size() member functions of std::initializer_list and std::array have identical signatures: constexpr size_type size() const noexcept; Both are constexpr . However, std::array::size() can be used in constexpr context, but std::initializer_list::size() can't: std::initializer_list<int> il{1, 2, 3, 4}; constexpr std::size_t il_size = il.size(); // (1) - fails with GCC and Clang (*) std::array<int, 4> arr{1, 2, 3, 4}; constexpr std::size_t arr_size = arr.size(); // (2) - OK (*) The error is: