One of core features of C++ is
function overloading. C distinguishes functions by name only. C++ uses name and types of parameters. Hence you can have many functions with identical name.
For example, while C has abs, labs, fabs, fabsf, and fabsl C++ has just abs and fabs.
All these do essentially same operation; only the type is different.
However, writing overloads manually for all types would be boring. Not to mention impossible. An author of algorithm library cannot possibly know all the types that someone in future could apply that algorithm to.
Enter the compiler. Rather than writing an overload for new type, you write
a template and the compiler writes the actual function (with concrete types) on the spot.
A template of an algorithm is
generic, yet keeps C++ strongly typed.
not sure why use pointers instead of just accessing the elements directly. |
1 2
|
for ( size_t b = start; b < last; ++b )
cout << d5[b];
|
Lets say that the code above is in a function. What do you need to pass to that function?
d5, start, and last
func( Container& d5, size_t start, size_t last );
That is just one more parameter than two pointers/iterators.
Look at set_intersection. It takes
five iterators. With container+indices it would need three containers and five indices.
Eight parameters.