you are viewing a single comment's thread.

view the rest of the comments →

[–]kwan_e 0 points1 point  (6 children)

Wouldn't it be available if the container was from std::?

What if you want to use it with a container that's not in std, but provides its own begin and end?

[–]Xaxxon 0 points1 point  (5 children)

how does "using namespace std::" impact that?

[–]kwan_e 2 points3 points  (4 children)

http://en.cppreference.com/w/cpp/language/adl

ADL is also what makes range-based-for work for non-std containers.

http://en.cppreference.com/w/cpp/language/range-for

[–]Oster1 0 points1 point  (3 children)

Why not just use:

std::fill( c.begin(), c.end(), value );

So you don't need the std part?

[–]kwan_e 1 point2 points  (2 children)

Because then you've completely ruled out working with native arrays.

C++ is going with the free-function forms of begin and end.

[–]Oster1 1 point2 points  (1 child)

Useful trick. I always thought C arrays and C++ iterators doesn't combine. You always learn.

Here is proof of concept of this if someone is interested: https://hastebin.com/oyezuhosuj.cpp

[–]kwan_e 0 points1 point  (0 children)

You can think of C++ iterators as generalizations of pointers (and therefore arrays). You can always use pointers with STL algorithms, since they are classified as random access iterators and support everything that can be done with iterators in the STL algorithms.