Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site













SourceForge.net Logo

Template Algorithms

 

template <class T> void Swap(T& a, T& b)

Swaps values. Specific types might specialize Swap.

 


 

template <class I> void IterSwap(I a, I b)

Swaps values pointed to by iterators. Specific types might specialize IterSwap.

 


 

template <class Tint sgn(T a)

Returns 1 if  a. is greater than zero, -1 if a is smaller than zero and zero if a is zero.

 


 

template <class TT tabs(T a)

Returns the absolute value of a.

 


 

template <class Tint cmp(const T& a, const T& b)

Returns 1 if a is greater than b, -1 if a is smaller than b and zero if a is equal than b.

 


 

template <class Rangevoid Reverse(Range& r)

template <class Rangevoid Reverse(Range&& r)

Reverses the order of values in a range.

 


 

template <class RangeValueTypeOf<RangeSum(const Range& r, const ValueTypeOf<Range>& zero)

Returns the sum of all elements in range r, with zero representing initial zero value. T must have defined operator+=.

 


 

template <class Rangetypename ValueTypeOf<RangeSum(const T& c)

Same as Sum(c, 0).

 


 

template <class Range, class Vint Count(const Range& r, const V& val)

Counts the number of elements in the Range r that are equal to val .

 


 

template <class Range, class Predicateint CountIf(const Range& r, const Predicate& p)

Counts the number of elements in the Range r that satisfy condition p.

 


 

template <class Range, class Predint FindBest(const Range& r, const Pred& pred)

Finds the most suitable element in a range r as specified by pred. E.g. if pred is std::less, finds minimum. If r is empty, returns -1.

 


 

template <class Rangeint FindMin(const Range& r)

Returns the index of minimal element of r, using std::less to compare elements. If r is empty, returns -1.

 


 

template <class Rangeconst ValueTypeOf<Range>& Min(const Range& r)

Returns the value of minimal element of r, using std::less to compare elements. If r is empty, behavior is undefined (ASSERT fails in debug).

 


 

template <class Rangeconst ValueTypeOf<Range>& Min(const Range& r, const ValueTypeOf<Range>& def)

Returns the value of minimal element of r, using std::less to compare elements. If r is empty, returns def.

 


 

template <class Rangeint FindMax(const Range& r)

Returns the index of maximal element of r, using std::greater to compare elements. If r is empty, returns -1.

 


 

template <class Rangeconst ValueTypeOf<Range>& Max(const Range& r)

Returns the value of maximal element of r, using std::less to compare elements. If r is empty, behavior is undefined (ASSERT fails in debug)..

 


 

template <class Rangeconst ValueTypeOf<Range>& Max(const Range& r, const ValueTypeOf<Range>& def)

Returns the value of maximal element of r, using std::less to compare elements. If r is empty, returns def.

 


 

template <class Range1, class Range2bool IsEqualRange(const Range1& a, const Range2& b)

Returns true if a and b are equal. operator== is used to compare elements. Ranges are considered equal if they have the same number of elements and for every element at index i: a[i] == b[i].

 


 

template <class Range1, class Range2int CompareRanges(const Range1& a, const Range2& b)

Lexicographically compares ranges a b, using SgnCompare to compare elements. SgnCompare is supposed to return value < 0 if first element is less than second, 0 if they are equal, >0 otherwise. Returns value <0, 0, >0 if a < b, a == b, a > b.

 


 

template <class Range, class V, class Cint FindMatch(const Range& r, const C& match, int from = 0)

Returns the index of first element for which predicate match is true. If not found, returns -1. Search starts at index from.

 


 

template <class Range, class Vint FindIndex(const Range& r, const V& value, int from = 0)

Returns the index of first element which is equal to value. If not found, returns -1. Search starts at index from.

 


 

template <class Range, class PredicateVector<intFindAll(const Range& r, Predicate match, int from = 0)

Returns the Vector of indices of  ALL elements for which match is true. Returned Vector is sorted in ascending order. Search starts at index from.

 


 

template <class Range, class T, class Lessint FindLowerBound(const Range& r, const T& val, const Less& less)

template <class Range, class Tint FindLowerBound(const Range& r, const T& val)

Finds the first index in sorted range r, which must be sorted by less predicate (or std::less in second overload), where val can be inserted without breaking the ordering.

 


 

template <class Range, class T, class Lint FindUpperBound(const Range& r, const T& val, const L& less)

template <class Range, class Tint FindUpperBound(const Range& r, const T& val)

Finds the last index in sorted range r, which must be sorted by less predicate (or std::less in second overload), where val can be inserted without breaking the ordering.

 


 

template <class Range, class T, class Lint FindBinary(const Range& r, const T& val, const L& less)

template <class Range, class Tint FindBinary(const Range& r, const T& val)

Finds the index of val in sorted range r, which must be sorted by less predicate (or std::less in second overload). If val is not present in r, return -1.

 


 

template <class Container, class Tvoid LruAdd(Container& lru, T value, int limit = 10)

This specialized algorithm is intended to manage Least-Recently-Used lists. lru has to be U++ array type (Vector, Array, InVector, InArray) and represents the list. value is the value to be eventually added to the list, limit is the maximum number of elements in the list. On call, if value is present in the lru, it is moved to the front. If it is not present, it is inserted to the front and the size of list is eventually reduced to limit, possibly removing the element at the end of list.

 

 

Last edit by cxl on 11/22/2016. Do you want to contribute?. T++