constexpr int maxValue1 = []()-> int { std::vector myVec = {1, 2, 4, 3}; std::sort(myVec.begin(), myVec.end()); return myVec.back(); }(); // immediately-invoked lambda std::cout << maxValue1 << std::endl; constexpr int maxValue = maxElement(); std::cout << s...
constexpr有个缺点:无法确定是在编译期还是运行时执行 #include<iostream>#include<ranges>#include<vector>#include<unordered_set>#include<algorithm>#include<format>#include<memory>#include<memory>constexprintconstexprFunction(intarg){returnarg*arg;}intmain(){static_assert(constexprFuncti...