Added documentation for the functions in algorithm.h.
svn-id: r33416
This commit is contained in:
parent
57c069ad47
commit
0a95a4814c
1 changed files with 49 additions and 5 deletions
|
@ -29,6 +29,11 @@
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies data from the range [first, last) to [dst, dst + (last - first)).
|
||||||
|
* It requires the range [dst, dst + (last - first)) to be valid.
|
||||||
|
* It also requires dst not to be in the range [first, last).
|
||||||
|
*/
|
||||||
template<class In, class Out>
|
template<class In, class Out>
|
||||||
Out copy(In first, In last, Out dst) {
|
Out copy(In first, In last, Out dst) {
|
||||||
while (first != last)
|
while (first != last)
|
||||||
|
@ -36,6 +41,13 @@ Out copy(In first, In last, Out dst) {
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies data from the range [first, last) to [dst - (last - first), dst).
|
||||||
|
* It requires the range [dst - (last - first), dst) to be valid.
|
||||||
|
* It also requires dst not to be in the range [first, last).
|
||||||
|
*
|
||||||
|
* Unlike copy copy_backward copies the data from the end to the beginning.
|
||||||
|
*/
|
||||||
template<class In, class Out>
|
template<class In, class Out>
|
||||||
Out copy_backward(In first, In last, Out dst) {
|
Out copy_backward(In first, In last, Out dst) {
|
||||||
while (first != last)
|
while (first != last)
|
||||||
|
@ -43,6 +55,15 @@ Out copy_backward(In first, In last, Out dst) {
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies data from the range [first, last) to [dst, dst + (last - first)).
|
||||||
|
* It requires the range [dst, dst + (last - first)) to be valid.
|
||||||
|
* It also requires dst not to be in the range [first, last).
|
||||||
|
*
|
||||||
|
* Unlike copy or copy_backward it does not copy all data. It only copies
|
||||||
|
* a data element when operator() of the op parameter returns true for the
|
||||||
|
* passed data element.
|
||||||
|
*/
|
||||||
template<class In, class Out, class Op>
|
template<class In, class Out, class Op>
|
||||||
Out copy_if(In first, In last, Out dst, Op op) {
|
Out copy_if(In first, In last, Out dst, Op op) {
|
||||||
while (first != last) {
|
while (first != last) {
|
||||||
|
@ -76,6 +97,9 @@ char *set_to(char *first, char *last, Value val) {
|
||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets all elements in the range [first, last) to val.
|
||||||
|
*/
|
||||||
template<class In, class Value>
|
template<class In, class Value>
|
||||||
In set_to(In first, In last, Value val) {
|
In set_to(In first, In last, Value val) {
|
||||||
while (first != last)
|
while (first != last)
|
||||||
|
@ -83,6 +107,10 @@ In set_to(In first, In last, Value val) {
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the first data value in the range [first, last) matching v.
|
||||||
|
* For data comperance it uses operator == of the data elements.
|
||||||
|
*/
|
||||||
template<class In, class T>
|
template<class In, class T>
|
||||||
In find(In first, In last, const T &v) {
|
In find(In first, In last, const T &v) {
|
||||||
while (first != last) {
|
while (first != last) {
|
||||||
|
@ -93,6 +121,10 @@ In find(In first, In last, const T &v) {
|
||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the first data value in the range [first, last) for which
|
||||||
|
* the specified predicate p returns true.
|
||||||
|
*/
|
||||||
template<class In, class Pred>
|
template<class In, class Pred>
|
||||||
In find_if(In first, In last, Pred p) {
|
In find_if(In first, In last, Pred p) {
|
||||||
while (first != last) {
|
while (first != last) {
|
||||||
|
@ -103,15 +135,22 @@ In find_if(In first, In last, Pred p) {
|
||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies the function f on all elements of the range [first, last).
|
||||||
|
* The processing order is from beginning to end.
|
||||||
|
*/
|
||||||
template<class In, class Op>
|
template<class In, class Op>
|
||||||
Op for_each(In first, In last, Op f) {
|
Op for_each(In first, In last, Op f) {
|
||||||
while (first != last) f(*first++);
|
while (first != last) f(*first++);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple sort function, modeled after std::sort.
|
/**
|
||||||
// Use it like this: sort(container.begin(), container.end()).
|
* Simple sort function, modeled after std::sort.
|
||||||
// Also work on plain old int arrays etc.
|
* Use it like this: sort(container.begin(), container.end()).
|
||||||
|
* Also works on plain old i.e. int arrays etc. For comperance
|
||||||
|
* operator < is used.
|
||||||
|
*/
|
||||||
template<class T>
|
template<class T>
|
||||||
void sort(T first, T last) {
|
void sort(T first, T last) {
|
||||||
if (first == last)
|
if (first == last)
|
||||||
|
@ -131,8 +170,13 @@ void sort(T first, T last) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Using this with: Common::Less from common/func.h
|
/**
|
||||||
// will give the same results as the function above.
|
* Simple sort function, modeled after std::sort.
|
||||||
|
* It compares data with the given comparator object comp.
|
||||||
|
*
|
||||||
|
* Note: Using this with: Common::Less from common/func.h
|
||||||
|
* will give the same results as the plain sort function.
|
||||||
|
*/
|
||||||
template<class T, class StrictWeakOrdering>
|
template<class T, class StrictWeakOrdering>
|
||||||
void sort(T first, T last, StrictWeakOrdering comp) {
|
void sort(T first, T last, StrictWeakOrdering comp) {
|
||||||
if (first == last)
|
if (first == last)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue