C++ constexpr算法所有编译器错误

C++ constexpr算法所有编译器错误,c++,algorithm,c++17,constexpr,C++,Algorithm,C++17,Constexpr,我有一小段代码: void all_of_examples() { using std::begin; using std::end; //C++17 //template< class InputIt, class UnaryPredicate > //constexpr bool all_of( InputIt first, InputIt last, UnaryPredicate p ); constexpr auto v2 = std::arra

我有一小段代码:

void all_of_examples() {
  using std::begin;
  using std::end;

  //C++17 
  //template< class InputIt, class UnaryPredicate >
  //constexpr bool all_of( InputIt first, InputIt last, UnaryPredicate p );

  constexpr auto v2 = std::array<int, 4>{1, 1, 1, 1};
  constexpr auto eqOne = [](int x) constexpr { 
                          constexpr int one = 1;
                          return x == one; 
                       };

  constexpr bool isAllV2 = std::all_of(begin(v2), end(v2), eqOne);

  std::cout << isAllV2 << std::flush << '\n';
}
void所有示例中的示例(){
使用std::begin;
使用std::end;
//C++17
//模板<类输入,类一元谓词>
//constexpr bool all_of(InputIt first,InputIt last,一元谓词p);
constexpr auto v2=std::数组{1,1,1};
constexpr auto eqOne=[](int x)constexpr{
constexpr int one=1;
返回x==1;
};
constexpr bool isAllV2=std::所有(开始(v2),结束(v2),eqOne);

std::cout
std::all_of
自c++20起仅为constexpr。而且libstdc++还不支持此功能

libc++从llvm-7开始就有支持,但即使使用clang,您也可能仍然使用libstdc++

见:


自C++20以来,所有的
都是
constrexp
,您是否使用了正确的开关?非常感谢您的回答!我完全错过了。