在C++11中(引用N3337),
std::begin()
和 std::end()
被指定为(§24.7 [iterator.range]/p2-3)。template <class C> auto begin(C& c) -> decltype(c.begin());
template <class C> auto begin(const C& c) -> decltype(c.begin());
2 返回:c.begin()
。
template <class C> auto end(C& c) -> decltype(c.end());
template <class C> auto end(const C& c) -> decltype(c.end());
3 返回:c.end()
。
template<class E> const E* begin(initializer_list<E> il) noexcept;
1 返回: il.begin()
。
template<class E> const E* end(initializer_list<E> il) noexcept;
返回il.end()
。
valarray
重载了。 - 101010valarray
没有成员函数begin()
和end()
,因此需要进行重载。 - T.C.initializer_list
并没有任何特殊的作用,我认为这并不是委员会决定指定额外重载的原因。 - T.C.