非成员函数模板 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/