-
Book Overview & Buying
-
Table Of Contents
C++ Memory Management
By :
The C++ standard library contains, among other gems, a set of algorithms. Each of these functions performs the tasks that a very well-written loop would do but with specific names, complexity guarantees, and optimizations. As such, let’s say we write the following:
int vals[]{ 2,3,5,7,11 };
int dest[5];
for(int i = 0; i != 5; ++i)
dest[i] = vals[i]; It is idiomatic in C++ to write the following instead:
int vals[]{ 2,3,5,7,11 };
int dest[5];
std::copy(begin(vals), end(vals), begin(dest)); The important thing to know here is that C++ sequences are of the form [begin,end), meaning that for all algorithms, the beginning iterator (here, begin(vals)) is included and the ending iterator (here, end(vals)) is excluded, making [begin,end) a half-open range. All algorithms in <algorithm> and in its cousin header, <numeric>, follow that simple convention.
What about ranges?
The <ranges> library is a major addition to the C...