C++11引入了没有constexpr说明符的std :: begin()非成员函数,然后C ++ 14更新为数组类型(T(&)[N])的constexpr-std :: begin()并附加constexpr-std :: cbegin()以用于通用容器类型(const C&)。
引自http://en.cppreference.com/w/cpp/iterator/begin。
引自http://en.cppreference.com/w/cpp/iterator/begin。
template< class T, size_t N >
constexpr T* begin( T (&array)[N] ); // (since C++14)
template< class C >
constexpr auto cbegin( const C& c ) -> decltype(std::begin(c)); // (since C++14)
因此,我们可以在C++14的constexpr函数中使用std::begin()
和/或std::cbegin()
来处理原始数组类型T[N]
(保留HTML标记)。
问题:
- C++14不允许在“标准容器”(例如
std::array
)中的constexpr上下文中使用非成员std::begin()
,因为它们没有提供constexpr-begin()
成员函数。我的解释正确吗? - 为什么非成员
std::cbegin()
有constexpr
说明符?对于用户提供的具有constexpr-begin()
成员函数的容器而言?
std::cbegin
调用std::begin
,但它不是constexpr
的...有两个例外:初始化列表重载和数组。 - T.C.cbegin
的constexpr
。 - Ben Voigt