When built using C++17/C++20 x64 gcc/clang, the below snippet yields a compile error whereas de-referencing the iterator directly via *std::max_element(std::begin(arr), std::end(arr)) works fine. Any ideas as to why? I've also observed similar behavior with other standard algorithms that have become constexpr since C++20, e.g. std::upper_bound
int main()
{
constexpr std::array<int,5> arr = {1,2,3,4,5};
constexpr auto it = std::max_element(std::begin(arr), std::end(arr));
}
source>:11:73: error: '(((std::array<int, 5>::const_pointer)(& arr.std::array<int, 5>::_M_elems)) + 16)' is not a constant expression
11 | constexpr auto it = std::max_element(std::begin(arr), std::end(arr));
|
std::begin/std::endareconstexpr, fed with aconstexpr std::array, andstd::max_elementisconstexpr, why can'tstd::max_element's output beconstexprtoo?*std:max_elementoutput ISconstexpr