在C ++ 11中sqrt是否定义为constexpr? [英] In C++11 is sqrt defined as constexpr?
问题描述
在C ++ 11中, std :: sqrt
定义为 constexpr
,即可以合法地从其他 constexpr
函数还是在编译时上下文(如数组大小或模板参数)中? g ++似乎允许(使用 -std = c ++ 0x
),但是鉴于c ++ 0x / c +,我不确定我是否可以将其视为权威+11支持仍然不完整。我似乎无法在Internet上找到任何东西的事实使我不确定。
In C++11 is std::sqrt
defined as constexpr
, i.e. can it legally be used from other constexpr
functions or in compile-time contexts like array sizes or template arguments? g++ seems to allow it (using -std=c++0x
), but I'm not sure I can take that as authoritative given that c++0x/c++11 support is still incomplete. The fact that I can't seem to find anything on the Internet makes me unsure.
似乎应该可以轻松地使用Google找出这一点,但是我已经尝试了(现在已经40分钟了……),却找不到任何东西。我可以找到一些将constexpr添加到标准库各个部分的建议(例如此),但与 sqrt
或其他数学函数无关。
It seems like this should be something one could easily find out using Google, but I've tried (for 40 minutes now...) and couldn't find anything. I could find several proposals for adding constexpr to various parts of the standard library (like for example this one), but nothing about sqrt
or other math functions.
推荐答案
std :: sqrt
未定义为 constexpr
,根据N3291的第26.8节:C ++ 11 FDIS(我怀疑他们之后将其添加到最终标准中)。可能可以编写这样的版本,但是标准库版本不是 constexpr
。
std::sqrt
is not defined as constexpr
, according to section 26.8 of N3291: the C++11 FDIS (and I doubt they added it to the final standard after that). One could possibly write such a version, but the standard library version is not constexpr
.
这篇关于在C ++ 11中sqrt是否定义为constexpr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!