First, the code has the following code fragment, which is used to accumulate constexpr std::array at compile time:
template <typename T, std::size_t N, typename O> constexpr T compile_time_accumulator(const std::array<T, N> const &A, const std::size_t i, const O& op, const T initialValue) { return (i < N) ? op(A[i], compile_time_accumulator(A, i + 1, op, initialValue)) : initialValue; }
and the following code example to check / modify it (i.e. what it evaluates at compile time):
constexpr std::array<int, 4> v {{4, 5, 6, 7}}; std::cout << std::integral_constant<int, compile_time_accumulator(v, 42, std::plus<int>())>::value << std::endl;
Live demo
Now, if you change the std::plus<int> operator using constexpr lambda:
constexpr auto lambda_plus = [] (int x, int y) { return x + y; };
and name it as shown below:
constexpr std::array<int, 4> v {{4, 5, 6, 7}}; std::cout << std::integral_constant<int, compile_time_accumulator(v, 42, lambda_plus)>::value << std::endl; ^^^^^^^^^^^
I get an error that lambda is not constexpr :
non-constexpr function call ''
Now, doing a litle study , I found that constexpr lambdas are not yet supported.
Q
Why, if constexpr lambdas are not supported, are we allowed to primarily define constexpr lambda?
Edit:
It seems that clang is not using code . So which compiler is right?