Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are begin(container) and end(container) standardized?

Are the non-member function templates begin(container) and end(container) part of C++0x? If so, in which header file do they live?

like image 844
fredoverflow Avatar asked Jul 30 '11 10:07

fredoverflow


1 Answers

Yes, but just as swap is defined in different places and depends on ADL, so are begin and end. The 'generic' versions are defined in <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]);

Note also that 24.6.5 says:

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>.

like image 200
Yakov Galka Avatar answered Sep 22 '22 15:09

Yakov Galka