If you look at, say, the definition of std::begin
:
template< class C >
auto begin( C& c ) -> decltype(c.begin());
You see that all it does is reference the begin()
anyway. I suppose a decent compiler will make the difference nil, so I guess it comes down to preference. Personally, I'd use cont.begin()
and cont.end()
just so that I wouldn't have to explain it to anybody :)
As Mooing Duck points out, however, std::begin
also works on arrays:
template< class T, size_t N >
T* begin( T (&array)[N] );
... so there is that to consider. If you are not using arrays, I'd go with my suggestion. However if you are unsure if what is passed is going to be an STL container, or an array of <T>
, then std::begin()
is the way to go.