c++ - begin(container) 和 end(container) 是否标准化?

标签 c++ iterator c++11 containers non-member-functions

非成员函数模板 begin(container)end(container) 是 C++0x 的一部分吗?如果是这样,它们位于哪个头文件中?

最佳答案

是的,但就像swap一样定义在不同的地方并取决于 ADL,begin 也是如此和 end . “通用”版本在 <iterator> 中定义:

// 24.6.5, range access:
template <class C> auto begin(C& c) -> decltype(c.begin());
template <class C> auto begin(const C& c) -> decltype(c.begin());
template <class C> auto end(C& c) -> decltype(c.end());
template <class C> auto end(const C& c) -> decltype(c.end());
template <class T, size_t N> T* begin(T (&array)[N]);
template <class T, size_t N> T* end(T (&array)[N]);

另请注意 24.6.5 说:

In addition to being available via inclusion of the <iterator> header, the function templates in 24.6.5 are available when any of the following headers are included: <array>, <deque>, <forward_list>, <list>, <map>, <regex>, <set>, <string>, <unordered_map>, <unordered_set>, and <vector>.

关于c++ - begin(container) 和 end(container) 是否标准化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6882561/

相关文章:

c++ - 在继承的情况下,编译器创建默认构造函数和用户创建默认构造函数之间的区别

c++ - 如何使用迭代器更改 for 循环中对象的属性?

c++ - 为什么在使用STL列表时不能使用此回文功能?

C++ 11线程初始化与成员函数编译错误

c++ - 问题解耦嵌套的 C++ 类

c++ - RcppArmadillo 中的向量化 log1p()

c++ - std::find的替代方法,它返回所有找到的值,而不是仅存在重复项的vector的第一个

c++ - C++0x 中的缩小转换。只是我,还是这听起来像是一个重大变化?

c++ - 为什么当内存中的类对象已经是二进制 (C/C++) 时进行序列化?

javascript - 使用 JavaScript 迭代器的困难