Simple Application Framework  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Functions
Saf::Algo::Range Namespace Reference

Algorithms and functions that execute on a range of elements. More...

Functions

template<class Iter >
void Advance (Iter &it, Size dist)
 Move an iterator by a specified distance.
template<class FwdIter , class Val >
bool AllEqualTo (FwdIter begin, FwdIter end, const Val &val)
 Check whether all elements in the range [begin, end) are equal to val.
template<class FwdIter , class Val >
bool AnyEqualTo (FwdIter begin, FwdIter end, const Val &val)
 Check whether any of the elements in the range [begin, end) is equal to val.
template<class FwdIterIn , class FwdIterOut >
FwdIterOut Copy (FwdIterIn begin, FwdIterIn end, FwdIterOut dest)
 Copy values from the range [begin, end) to the sequence starting with dest.
template<class FwdIter , class Val >
Size Count (FwdIter begin, FwdIter end, const Val &val)
 Count elements with value val in the sequence [begin, end).
template<class FwdIter , class Pred >
Size CountIf (FwdIter begin, FwdIter end, Pred pred)
 Count elements in the sequence [begin, end) for which the predicate pred holds.
template<class Iter >
Size Distance (Iter begin, Iter end)
 Calculate the number of elements in the range [begin, end).
template<class FwdIter1 , class FwdIter2 >
bool Equal (FwdIter1 r1Begin, FwdIter1 r1End, FwdIter2 r2Begin)
 Check whether two ranges of the same length contain the same values.
template<class FwdIter , class Val >
void Fill (FwdIter begin, FwdIter end, const Val &val)
 Assign value val to all elements in the range [begin, end).
template<class FwdIter , class Val >
void FillFirst (FwdIter first, Size num, const Val &val)
 Assign value val to first num elements in the sequence starting with first.
template<class FwdIter , class Func >
Func ForEach (FwdIter begin, FwdIter end, Func func)
 Apply functor func to all elements in the range [begin, end).
template<class FwdIter1 , class FwdIter2 >
bool Identical (FwdIter1 r1Begin, FwdIter1 r1End, FwdIter2 r2Begin, FwdIter2 r2End)
 Check whether two ranges have the same length and contain the same values.
template<class BidIter >
void Reverse (BidIter begin, BidIter end)
 Reverse the values in the range [begin,end).
template<class Iter >
void Rotate (Iter begin, Iter middle, Iter end)
 Rotate the elements in the range [begin, end) such that the element pointed to by middle is first.

Detailed Description

Algorithms and functions that execute on a range of elements.

See also:
Saf::Math::Range.

Function Documentation

template<class Iter >
void Saf::Algo::Range::Advance ( Iter &  it,
Size  dist 
) [inline]

Move an iterator by a specified distance.

Properties:

  • Minimum iterator category: Input.
  • Time complexity: $ \mathcal{O}(1) $ for random-access iterators, $ \mathcal{O}(\mathrm{dist}) $ otherwise.
template<class FwdIter , class Val >
bool Saf::Algo::Range::AllEqualTo ( FwdIter  begin,
FwdIter  end,
const Val &  val 
) [inline]

Check whether all elements in the range [begin, end) are equal to val.

Properties:

  • Minimum iterator category: Forward.
  • Worst-case time complexity: $ \mathcal{O}(\mathrm{Distance(begin, end)}) $.
template<class FwdIter , class Val >
bool Saf::Algo::Range::AnyEqualTo ( FwdIter  begin,
FwdIter  end,
const Val &  val 
) [inline]

Check whether any of the elements in the range [begin, end) is equal to val.

Properties:

  • Minimum iterator category: Forward.
  • Worst-case time complexity: $ \mathcal{O}(\mathrm{Distance(begin, end)}) $.
template<class FwdIterIn , class FwdIterOut >
FwdIterOut Saf::Algo::Range::Copy ( FwdIterIn  begin,
FwdIterIn  end,
FwdIterOut  dest 
) [inline]

Copy values from the range [begin, end) to the sequence starting with dest.

Properties:

  • Minimum iterator category: Forward.
  • Time complexity: $ \mathcal{O}(\mathrm{Distance(begin, end)}) $.
Returns:
Iterator to the end of the destination range.
Warning:
There must be enough allocated room in the destination range.
template<class FwdIter , class Val >
Size Saf::Algo::Range::Count ( FwdIter  begin,
FwdIter  end,
const Val &  val 
) [inline]

Count elements with value val in the sequence [begin, end).

Properties:

  • Minimum iterator category: Forward.
  • Time complexity: $ \mathcal{O}(\mathrm{Distance(begin, end)}) $.
template<class FwdIter , class Pred >
Size Saf::Algo::Range::CountIf ( FwdIter  begin,
FwdIter  end,
Pred  pred 
) [inline]

Count elements in the sequence [begin, end) for which the predicate pred holds.

Properties:

  • Minimum iterator category: Forward.
  • Time complexity: $ \mathcal{O}(\mathrm{Distance(begin, end)}) $.
template<class Iter >
Size Saf::Algo::Range::Distance ( Iter  begin,
Iter  end 
) [inline]

Calculate the number of elements in the range [begin, end).

Properties:

  • Minimum iterator category: Forward.
  • Time complexity: $ \mathcal{O}(1) $ for random-access iterators, linear in the length of the sequence otherwise.
template<class FwdIter1 , class FwdIter2 >
bool Saf::Algo::Range::Equal ( FwdIter1  r1Begin,
FwdIter1  r1End,
FwdIter2  r2Begin 
) [inline]

Check whether two ranges of the same length contain the same values.

Properties:

  • Minimum iterator category: Forward.
  • Time complexity: $ \mathcal{O}(\mathrm{Distance(r1Begin, r1End)}) $.
Parameters:
[in]r1BeginIterator to the beginning of the first sequence.
[in]r1EndIterator to the end of the first sequence.
[in]r2BeginIterator to the beginning of the second sequence. The sequence must have the same length as the first one.
template<class FwdIter , class Val >
void Saf::Algo::Range::Fill ( FwdIter  begin,
FwdIter  end,
const Val &  val 
) [inline]

Assign value val to all elements in the range [begin, end).

Properties:

  • Minimum iterator category: Forward.
  • Time complexity: $ \mathcal{O}(\mathrm{Distance(begin, end)}) $.
template<class FwdIter , class Val >
void Saf::Algo::Range::FillFirst ( FwdIter  first,
Size  num,
const Val &  val 
) [inline]

Assign value val to first num elements in the sequence starting with first.

Properties:

  • Minimum iterator category: Forward.
  • Time complexity: $ \mathcal{O}(\mathrm{num}) $.
template<class FwdIter , class Func >
Func Saf::Algo::Range::ForEach ( FwdIter  begin,
FwdIter  end,
Func  func 
) [inline]

Apply functor func to all elements in the range [begin, end).

Properties:

  • Minimum iterator category: Forward.
  • Time complexity: $ \mathcal{O}(\mathrm{Distance(begin, end)}) $.
template<class FwdIter1 , class FwdIter2 >
bool Saf::Algo::Range::Identical ( FwdIter1  r1Begin,
FwdIter1  r1End,
FwdIter2  r2Begin,
FwdIter2  r2End 
) [inline]

Check whether two ranges have the same length and contain the same values.

Properties:

  • Minimum iterator category: Forward.
  • Time complexity: $ \mathcal{O}(\mathrm{min(Distance(r1Begin, r1End), Distance(r2Begin, r2End))}) $.
Parameters:
[in]r1BeginIterator to the beginning of the first sequence.
[in]r1EndIterator to the end of the first sequence.
[in]r2BeginIterator to the beginning of the second sequence.
[in]r2EndIterator to the end of the second sequence.
template<class BidIter >
void Saf::Algo::Range::Reverse ( BidIter  begin,
BidIter  end 
) [inline]

Reverse the values in the range [begin,end).

Properties:

  • Minimum iterator category: Bidirectional.
  • Time complexity: $ \mathcal{O}(\mathrm{Distance(begin, end)}) $.
template<class Iter >
void Saf::Algo::Range::Rotate ( Iter  begin,
Iter  middle,
Iter  end 
) [inline]

Rotate the elements in the range [begin, end) such that the element pointed to by middle is first.

Properties:

  • Minimum iterator category: Forward.
  • Time complexity: $ \mathcal{O}(\mathrm{Distance(begin, end)}) $.