Why this does not work:
constexpr initializer_list<int> ilist = {1,2,3,4}; constexpr int my_min = min(ilist);
While doing this:
constexpr int my_min = min({1,2,3,4});
I base my code on the constexpr std :: min () function, as shown here , and I use clang3.5.0 for the compiler (g ++ 4.9.1 does not seem to know about constexpr std :: min ()).
I can not understand the error I am getting:
clang35 -stdlib=libc++ -std=c++14 test.cpp -o test; test.cpp:158:35: error: constexpr variable 'ilist' must be initialized by a constant expression constexpr initializer_list<int> ilist = {1,2,3,4}; ^ ~~~~~~~~~ test.cpp:158:35: note: pointer to subobject of temporary is not a constant expression test.cpp:158:43: note: temporary created here constexpr initializer_list<int> ilist = {1,2,3,4}; ^ test.cpp:159:17: error: constexpr variable 'my_min' must be initialized by a constant expression constexpr int my_min = min(ilist); ^ ~~~~~~~~~~ test.cpp:159:30: note: initializer of 'ilist' is not a constant expression constexpr int my_min = min(ilist); ^ test.cpp:159:30: note: in call to 'initializer_list(ilist)' test.cpp:158:35: note: declared here constexpr initializer_list<int> ilist = {1,2,3,4};
source share