【发布时间】:2017-01-07 23:58:04
【问题描述】:
我受限于编写 C++11 代码,但我想使用 std::cbegin()。所以,我正在查看 GCC 5.4.0 的实现,在我的系统上的 /usr/include/c++/5/bits/range_access.h 中,我想我可能会写一些类似的东西,我看到了:
template<class _Container>
inline constexpr auto
cbegin(const _Container& __cont) noexcept(noexcept(std::begin(__cont)))
-> decltype(std::begin(__cont))
{ return std::begin(__cont); }
这就是它的全部吗?我错过了什么吗?如果是这样,为什么它不是像std::begin() 这样的 C++11 的一部分?
【问题讨论】:
-
至于为什么它不是一部分:因为你没有及时写出提案。你真丢脸:-)
-
我不太明白这个问题。除了“是”之外,您还期待什么其他答案?
-
添加
std::begin/end的主要原因之一是可以在 range-for 循环中使用普通数组(没有begin/end成员函数)。std::cbegin/cend不是必需的。