gpt4 book ai didi

c++ - std::max() 和 std::min() 不是 constexpr

转载 作者:IT老高 更新时间:2023-10-28 12:37:45 25 4
gpt4 key购买 nike

我刚刚注意到新标准定义了 min(a,b)max(a,b) without constexpr .

25.4.7 中的示例,[alg.min.max]:

template<class T> const T& min(const T& a, const T& b);
template<class T> T min(initializer_list<T> t);

这不是很遗憾吗?我本来想写的

char data[ max(sizeof(A),sizeof(B)) ];

而不是

char data[ sizeof(A) > sizeof(B) ? sizeof(A) : sizeof(B) ];
char data[ MAX(sizeof(A),sizeof(B)) ]; // using a macro

那些不能是constexpr的任何原因?

最佳答案

std::min 和 std::max are constexpr在 C++14 中,这显然意味着(这些天)没有充分的理由不让它们 constexpr。问题解决了:-)

关于c++ - std::max() 和 std::min() 不是 constexpr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5605142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com