Quick A: Yes.
A classic on SO, just re-asked yesterday:
When to use std::begin and std::end instead of container specific versions
Are there any general preferences or rules that explain when container specific versions of
beginandendshould be used instead of free functionsstd::beginandstd::end?It is my understanding that if the function is a template whereby the container type is a template parameter then
std::beginandstd::endshould 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)andstd::end(cont)or should the container's member functionscont.begin()andcont.end()be preferred?Am I correct in assuming that there is no benefit in performance by calling
cont.end()overstd::end(cont)?

Add a Comment
Comments are closed.