Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

begin(), end() annoyance in STL algorithms

Tags:

c++

algorithm

stl

I like STL algorithms, and prefer use algorithms rather than usual loops.
Almost all STL algorithms are usually used as:

std::algorithm_name( container.begin(), container.end(), ..... )  

container.begin(), container.end() - is one of most popular words pair in my projects.

Does anybody have the same problem?
How do you Guys solve this problem?
What could you propose to avoid this duplication? I see a few ways for solution, but all of them have different limitations (macro usage, not compatible with usual pointers, etc.).

like image 779
bayda Avatar asked Mar 29 '09 11:03

bayda


People also ask

How many algorithms are there in STL?

Standard Template Library (STL) IV - Algorithms - 2020. The standard algorithms are found in <algorithms>. There are about 60 standard algorithms are defined in <algorithms>.

What are STL algorithms?

The Standard Template Library, or STL, is a C++ library of container classes, algorithms, and iterators; it provides many of the basic algorithms and data structures of computer science. The STL is a generic library, meaning that its components are heavily parameterized: almost every component in the STL is a template.

What is STL algorithms in C++?

The Standard Template Library (STL) is a set of C++ template classes to provide common programming data structures and functions such as lists, stacks, arrays, etc. It is a library of container classes, algorithms, and iterators. It is a generalized library and so, its components are parameterized.


1 Answers

The next C++ standard, C++0X (where X stands for, hopefully, 9) will add the possibility to change from iterator perspective to container perspective. You will be able to do eg.

std::sort(my_vec);

If you cant wait for this I would recommend you to look at: Boost.Range

And if you are a really interested in iterators/ranges I would recommend you to read Andrei's "iterators must go"

like image 158
Schildmeijer Avatar answered Sep 22 '22 16:09

Schildmeijer