Why not the overload provided in standard library functions with iterator parameters?

The standard library has many functions that are structured as follows:

std::foo(begin(x), end(x), bar);

My concern is that in 99% of cases, arguments begin and end. Why these functions do not have overloads, which, of course, will be used more often:

std::foo(x, bar);

Is this a limitation of language or design, or is it oversight? Thank.

+4
source share
1 answer

Take a look at the old Herb Sutter column “Why aren't there container-based algorithms?”

The problem is that if you already have, for example,

template<class Iter>             std::sort(Iter, Iter)       // (1)
template<class Iter, class Pred> std::sort(Iter, Iter, Pred) // (2)

then entering

template<class Container>             std::sort(Container)       // (3)
template<class Container, class Pred> std::sort(Container, Pred) // (4)

++ 98 (1) (4): iterator a const_iterator sort(), (4) (1).

++ 11 SFINAE , , , , ++.

+5

Source: https://habr.com/ru/post/1531870/


All Articles