T *
iterators.
find()
is easy, but how about find_rightmost_subsequence()
?
std::
to make it clear you're using generic algorithms.
<algorithm>
.
find(v), find_first_of(v), adjacent_find()
search(), search_n(), find_end()
mismatch(),equal()
count(v)
values in a sequence.
for_each(f)
applies a function to each value in a sequence.
accumulate()
inner_product()
partial_sum()
adjacent_difference()
transform(f), replace(v1, v2), fill(v), generate(f)
remove(v), unique()
reverse(), rotate(), random_shuffle(), partition()
std::vector<int> iv1(10, 0); std::vector<int> iv2; std::copy(iv1.start(), iv1.end(), iv2.start);
This goes (or should go) boom. Why?
std::vectoriv1(10, 0); std::vector iv2(iv1);
Know your tools.
sort(), stable_sort(), partial_sort()
nth_element(), binary_search(), lower_bound(), upper_bound(), ...
merge()
two sorted sequences into one.
set_union(), set_intersection(), ...
push_heap(), pop_heap(), make_heap(), ...
less()
is not obvious.
less()
must be a trichotomy.
<
is a trichotomy, <=
is not.
If both a < b
and b < b
are false
then (a == b).
_if
convention distinguishes value-predicate algorithms.
find(start, end, value)
Return an iterator to the leftmost occurrence of value
in the sequence,
or end
if there's no such value.
find_if(start, end, predicate)
Return an iterator to the leftmost occurrence of a value in the sequence that
causes the predicate to return true, or end
if there's no such value.
_copy
convention indicates non-mutating mutating algorithms.
reverse(start, end)
Reverse the order of the elements in the given sequence.
reverse(start, end, new_start)
Copy the reversed sequence into the sequence starting at new_start
.
for(unsigned i = 0; i < str.size(); i++) str[i] = std::tolower(str[i])
std::transform(str.begin(), str.end(), str.begin(), std::tolower);
std::copy(v1.begin(), v1.end(), v2.begin())
v2.assign(v1.begin(), v2.end())
v2.insert(v2.end(), v1.begin(), v1,end())
v2.assign()
changes v2
's size; std::copy()
can't (without
help).
This page last modified on 16 October 2002.