c++ - begin() 在 C++17 中是 constexpr 而在 C++14 中是 cbegin() 吗?
问题描述
根据cppreference,std::cbegin()
对于容器是在 C++14 中引入的constexpr
- 但是std::begin()
,在 C++11 中引入的,直到 C++17 之前仍然是非常数的。
真的吗?这似乎很不平衡。这是什么原因?
解决方案
过载
template< class T, std::size_t N >
constexpr T* begin( T (&array)[N] ) noexcept;
在 C++14 中是 constexpr,所以在 C++14std::cbegin
中调用std::begin
的 也是 constexpr。
对于非数组,std::cbegin
在 C++14 中的常量表达式中不可用,即使函数模板仍标记为constexpr
.
推荐阅读
- apache-nifi - InvalidMagicIdException:无法在 infinispan 中添加缓存
- google-apps-script - 谷歌表格脚本编辑器 - 如果 E 列中有特定文本,则发送电子邮件
- vim - 如何输入与上行字符数一样多的连字符?
- html - react 使用 html4、html5 还是 jsx?
- java - json反序列化对于有效格式失败
- python - 了解 unicodedata.normalize() 的 unistr
- mysql - 如何在执行 sql 查询时根据整数变量设置字符串值?
- c# - 查找 2 个数据集之间的值差异并在 ASPX 页面上突出显示差异
- javascript - 如何将普通的 javascript 代码转换为使用事件处理的角度组件特定代码
- python - 如何使用 Python 从 Json 文件中的嵌套列表中提取对象?