Are there any general preferences or rules that explain when container specific versions of begin and end should be used instead of free functions std::begin
and std::end
?
It is my understanding that if the function is a template whereby the container type is a template parameter then std::begin
and std::end
should be used, i.e.:
template<class T> void do_stuff( const T& t )
{
std::for_each( std::begin(t), std::end(t), /* some stuff */ );
}
What about in other scenarios such as a standard / member function where the type of container is known? Is it still better practice to use std::begin(cont)
and std::end(cont)
or should the container's member functions cont.begin()
and cont.end()
be preferred?
Am I correct in assuming that there is no benefit in performance by calling cont.end()
over std::end(cont)
?
using std::begin; begin(c);
to let ADL do its work. – Barling