Algorithms Library
[Libraries]


Detailed Description

Created: 13th January 2007 Updated: 13th January 2007.

This library contains algorithms .


Functions

template<typename I, typename O>
copy_n (I src, size_t n, O dest)
 Copies N elements from the range [src, src + n) to the range [dest, dest + n).
template<typename I, typename T>
void replace_n (I src, size_t n, T const &oldValue, T const &newValue)
 Copies N elements from the range [src, src + n) to the range [dest, dest + n).
template<typename C, typename V>
void fill_all (C &container, V const &value)
 Invokes std::for_each() on the range of items in a container.
template<typename T, size_t N, typename V>
void fill_all (T(&ar)[N], V const &value)
 Invokes std::for_each() on the range of items in an array.
template<typename C, typename UF>
UF for_all (C &container, UF func)
 Invokes std::for_each() on the range of items in a container.
template<typename T, size_t N, typename UF>
UF for_all (T(&ar)[N], UF func)
 Invokes std::for_each() on the range of items in an array.
template<typename C, typename UF>
UF for_all_r (C &container, UF func)
 Invokes std::for_each() on the reverse range of items in a container.
template<typename C, typename O>
copy_all (C &container, O dest)
 Invokes std::copy() on all the items in a container.
template<typename T, size_t N, typename O>
copy_all (T(&ar)[N], O dest)
 Invokes std::copy() on the range of items in an array.
template<typename I, typename UF>
UF for_each_preinc (I first, I last, UF func)
 Carries out for_each on the range, using pre-increment on the iterator.
template<typename I, typename UF>
UF for_each_postinc (I first, I last, UF func)
 Carries out for_each on the range, using post-increment on the iterator.
template<typename I, typename P>
size_t for_each_count_success (I first, I last, P pred)
 Counts the number of items in the sequence which the predicate is true.
template<typename I, typename V>
V const & for_each_set_value (I begin, I end, V const &value)
 Sets the value of all items in the sequence.
template<typename O, typename V, typename P>
V const & for_each_set_value_if (O begin, O end, V const &value, P pred)
 Sets the value of all items in the sequence.
template<typename I, typename O>
void pod_copy (I *first, I *last, O *dest)
 Copies one range of POD (Plain Old Data) entities to another.
template<typename I, typename O>
void pod_copy_n (O *dest, I *src, size_t n)
 Copies one range of POD (Plain Old Data) entities to another.
template<typename I, typename O>
void pod_move (I *first, I *last, O *dest)
 Copies one range of POD (Plain Old Data) entities to another, where the two may potentially overlap.
template<typename I, typename O>
void pod_move_n (O *dest, I *src, size_t n)
 Copies one range of POD (Plain Old Data) entities to another, where the two may potentially overlap.
template<typename T, typename V>
void pod_fill_n (T *dest, size_t n, V const &value)
 Sets all the elements in a range of POD (Plain Old Data) to a given value.
template<typename I>
void std_advance (I &i, ss_ptrdiff_t n)
 Equivalent to std::advance().
template<typename I, typename O>
std_copy (I first, I last, O dest)
 Equivalent to std::copy().
template<typename I, typename UP>
size_t std_count_if (I first, I last, UP pred)
 Equivalent to std::count_if().
template<typename O, typename V>
void std_fill (O first, O last, V const &value)
 Equivalent to std::fill().
template<typename O, typename V>
void std_fill_n (O dest, size_t n, V const &value)
 Equivalent to std::fill_n().
template<typename I, typename V>
std_find (I first, I last, V const &value)
 Equivalent to std::find().
template<typename I, typename UP>
std_find_if (I first, I last, UP pred)
 Equivalent to std::find_if().
template<typename I, typename UF>
UF std_for_each (I first, I last, UF func)
 Equivalent to std::for_each().
template<typename I, typename T>
void std_replace (I first, I last, T const &valFind, T const &valReplace)
 Equivalent to std::replace().
template<typename RI>
void sort (RI first, RI last)
 Equivalent to std::sort().
template<typename RI, typename BP>
void std_sort (RI first, RI last, BP pred)
 Equivalent to std::sort().
template<typename I, typename O, typename UF>
std_transform (I first, I last, O dest, UF func)
 Equivalent to std::transform().
template<typename FI, typename BP>
FI std_unique (FI first, FI last, BP pred)
 Equivalent to std::unique().
template<typename FI>
FI std_unique (FI first, FI last)
 Equivalent to std::unique().
template<typename FI, typename OI>
OI std_unique_copy (FI first, FI last, OI dest)
 Equivalent to std::unique_copy().
template<typename FI, typename OI, typename BP>
OI std_unique_copy (FI first, FI last, OI dest, BP pred)
 Equivalent to std::unique_copy().
template<typename I, typename O, typename UP>
copy_if (I first, I last, O dest, UP pred)
 Copies elements from one range to another that satisfy a predicate.
template<typename I, typename UF, typename UP>
UF for_each_if (I first, I last, UF func, UP pred)
 Applies the function to all items in a range that satisfy a predicate.
template<typename O, typename V, typename UP>
void fill_if (O first, O last, V const &value, UP pred)
 Sets the value of all items in a range that satisfy a predicate.
template<typename I>
std::pair< I, I > find_first_duplicate (I first, I last)
 Finds the first duplicate item in the unordered sequence [first, last).
template<typename I, typename BP>
std::pair< I, I > find_first_duplicate (I first, I last, BP pred)
template<typename FI>
FI unordered_unique (FI first, FI last)
template<typename FI, typename BP>
FI unordered_unique (FI first, FI last, BP pred)
template<typename FI, typename BP>
FI unordered_unique_if (FI first, FI last, BP pred)
template<typename FI, typename OI>
OI unordered_unique_copy (FI first, FI last, OI dest)
template<typename C, typename BP>
void remove_duplicates_from_unordered_sequence (C &container, BP pred)
 This algorithm removes duplicate entries from unordered sequences.
template<typename C>
void remove_duplicates_from_unordered_sequence (C &container)
 This algorithm removes duplicate entries from unordered sequences.
template<typename I>
skip_equal (I first, I last)
 Skips along from a given iteration point to the first subsequent iteration point whose value is not equal to that of the starting point.
template<typename I1, typename I2>
bool unordered_includes (I1 first1, I1 last1, I2 first2, I2 last2)
 Determines whether all elements from the range [first2, last2) are contained within the range [first1, last1).


Function Documentation

O stlsoft::copy_all ( T(&)  ar[N],
dest 
) [inline]

Invokes std::copy() on the range of items in an array.

Parameters:
ar The array
dest The output iterator to which each element will be copied

References stlsoft::std_copy().

O stlsoft::copy_all ( C &  container,
dest 
) [inline]

Invokes std::copy() on all the items in a container.

Parameters:
container The container instance
dest The output iterator to which each element will be copied

References stlsoft::std_copy().

O stlsoft::copy_if ( first,
last,
dest,
UP  pred 
) [inline]

Copies elements from one range to another that satisfy a predicate.

Copies each of the N elements in the source range [first, last) to the destination range - of available length [dest, dest + N) - for which the expression pred(*(i + n)) hold true, where i is the nth element in the range

Parameters:
first The start of the (unordered) sequence
last The (one past the) end point of the sequence
dest The output iterator to which the copies are written
pred The predicate used to determine whether the element in the input sequence is to be written to the output iterator

O stlsoft::copy_n ( src,
size_t  n,
dest 
) [inline]

Copies N elements from the range [src, src + n) to the range [dest, dest + n).

Parameters:
src The iterator copied from
n The number of elements copied
dest The iterator copied to

void stlsoft::fill_all ( T(&)  ar[N],
V const &  value 
) [inline]

Invokes std::for_each() on the range of items in an array.

Parameters:
ar The array
value The value to set to each element in the array

void stlsoft::fill_all ( C &  container,
V const &  value 
) [inline]

Invokes std::for_each() on the range of items in a container.

Parameters:
container The container instance
value The value that to assign to each element in the container

void stlsoft::fill_if ( first,
last,
V const &  value,
UP  pred 
) [inline]

Sets the value of all items in a range that satisfy a predicate.

Assigns the value v to each of the N elements in the range [first, last) for which the expression pred(*(i + n)) hold true, where i is the nth element in the range

Parameters:
first The start of the sequence
last The last of the sequence
value The value to be assigned to each selected element
pred The predicate used to determine whether the value is to be assigned to the element in the input sequence

Referenced by stlsoft::for_each_set_value_if().

std:: pair<I, I> stlsoft::find_first_duplicate ( first,
last 
) [inline]

Finds the first duplicate item in the unordered sequence [first, last).

If a duplicate is found, the return value is a pair of the iterators referring to the first and second elements comprising the duplicate. If no duplicate is found, the return value is a pair containing the last iterator in both its members

Parameters:
first The start of the (unordered) sequence
last The (one past the) end point of the sequence
Note:
This algorithm works for ordered sequences, but std::adjacent_find is more suitable for such cases

References stlsoft_ns_qual_std.

UF stlsoft::for_all ( T(&)  ar[N],
UF  func 
) [inline]

Invokes std::for_each() on the range of items in an array.

Parameters:
ar The array
func The function to be applied to each element in the array

References stlsoft::std_for_each().

UF stlsoft::for_all ( C &  container,
UF  func 
) [inline]

Invokes std::for_each() on the range of items in a container.

Parameters:
container The container instance
func The function to be applied to each element in the container

References stlsoft::std_for_each().

UF stlsoft::for_all_r ( C &  container,
UF  func 
) [inline]

Invokes std::for_each() on the reverse range of items in a container.

Parameters:
container The container instance
func The function to be applied to each element in the container

References stlsoft::std_for_each().

size_t stlsoft::for_each_count_success ( first,
last,
pred 
) [inline]

Counts the number of items in the sequence which the predicate is true.

Note:
This function is identical in semantics to std::count_if(). If you are compiling in the context of a standard compliant library, you should prefer std::count_if().
Parameters:
first The start of the range to count
last The end of the range to count
pred The predicate

References stlsoft::std_count_if().

UF stlsoft::for_each_if ( first,
last,
UF  func,
UP  pred 
) [inline]

Applies the function to all items in a range that satisfy a predicate.

Applies the function f to each of the N elements in the source range [first, last) for which the expression pred(*(i + n)) hold true, where i is the nth element in the range

Parameters:
first The start of the (unordered) sequence
last The (one past the) end point of the sequence
func The function type to be applied to each selected element
pred The predicate used to determine whether the function is to be applied to the element in the input sequence

UF stlsoft::for_each_postinc ( first,
last,
UF  func 
) [inline]

Carries out for_each on the range, using post-increment on the iterator.

Parameters:
first The start of the sequence
last The end of the sequence
func The function

UF stlsoft::for_each_preinc ( first,
last,
UF  func 
) [inline]

Carries out for_each on the range, using pre-increment on the iterator.

Parameters:
first The start of the sequence
last The end of the sequence
func The function

V const& stlsoft::for_each_set_value ( begin,
end,
V const &  value 
) [inline]

Sets the value of all items in the sequence.

Note:
This function is identical in semantics to std::fill(), except that it returns the value. If you are compiling in the context of a standard compliant library, and do not need the value returned, you should prefer std::fill().
Parameters:
begin The start of the sequence
end The end of the sequence
value The value to be applied to item N, for each N in [begin, end)

References stlsoft::std_fill().

V const& stlsoft::for_each_set_value_if ( begin,
end,
V const &  value,
pred 
) [inline]

Sets the value of all items in the sequence.

Deprecated:
This is the old name for fill_if().
Parameters:
begin The start of the sequence
end The end of the sequence
value The value to be applied to item N, for each N in [begin, end), when pred(*(begin + N)) evaluates non-zero
pred The predicate that determines whether the value is to be modified

References stlsoft::fill_if().

void stlsoft::pod_copy ( I *  first,
I *  last,
O *  dest 
) [inline]

Copies one range of POD (Plain Old Data) entities to another.

This algorithm has the same semantics as std::copy(), but it uses memcpy() to copy elements en bloc, rather than copy assignment of one element at a time.

  const int8_t  src_bytes[3] = { -1, 0, +1 };
  int8_t        dest_bytes[3];

  pod_copy(&src_bytes[0], &src_bytes[0] + STLSOFT_NUM_ELEMENTS(src_bytes), &dest_bytes[0]);
  assert(0 == memcmp(&src_bytes[0], &dest_bytes[0], sizeof(src_bytes)));

Note:
The implementation uses static assertions to ensure that the source and destination element types are the same size.

The implementation uses constraints ensure sure that the source and destination element types are POD

Parameters:
first Contiguous Iterator marking the start of the source range
last Contiguous Iterator marking the one-past-the-end of the source range
dest Contiguous Iterator marking the start of the source range

References ss_typename_type_k, stlsoft::std_copy(), and STLSOFT_STATIC_ASSERT.

void stlsoft::pod_copy_n ( O *  dest,
I *  src,
size_t  n 
) [inline]

Copies one range of POD (Plain Old Data) entities to another.

This algorithm uses memcpy() to copy elements en bloc, rather than copy assignment of one element at a time.

  const int8_t  src_bytes[3] = { -1, 0, +1 };
  int8_t        dest_bytes[3];

  pod_copy_n(&dest_bytes[0], &src_bytes[0], STLSOFT_NUM_ELEMENTS(src_bytes));
  assert(0 == memcmp(&src_bytes[0], &dest_bytes[0], sizeof(src_bytes)));

Note:
The implementation uses static assertions to ensure that the source and destination element types are the same size.

The implementation uses constraints ensure sure that the source and destination element types are POD

Parameters:
dest Contiguous Iterator marking the start of the source range
src Contiguous Iterator marking the start of the source range
n Number of elements in the range

References ss_typename_type_k, stlsoft::std_copy(), and STLSOFT_STATIC_ASSERT.

Referenced by basic_environment_block::basic_environment_block(), basic_file_path_buffer< C >::basic_file_path_buffer(), basic_environment_block::operator=(), and basic_file_path_buffer< C >::operator=().

void stlsoft::pod_fill_n ( T *  dest,
size_t  n,
V const &  value 
) [inline]

Sets all the elements in a range of POD (Plain Old Data) to a given value.

This algorithm has the same semantics as std::fill_n(), but it uses memset() for some types to set the range of elements, rather than copy assignment of one element at a time.

  const int8_t  src_bytes[3] = { 3, 3, 3 };
  int8_t        dest_bytes[3];

  pod_fill_n(&dest_bytes[0], STLSOFT_NUM_ELEMENTS(src_bytes), 3);
  assert(0 == memcmp(&src_bytes[0], &dest_bytes[0], sizeof(src_bytes)));

The generic overload uses std::fill_n(), so performance is likely to be identical to std::fill_n() in the general case. However, it is overloaded to use memset() on char, signed char and unsigned char types, for which performance gains are likely.

Parameters:
dest Contiguous Iterator marking the start of the source range
n Number of elements in the range
value Value to which each element in dest[0, n) will be set

References ss_typename_type_k, and stlsoft::std_fill_n().

void stlsoft::pod_move ( I *  first,
I *  last,
O *  dest 
) [inline]

Copies one range of POD (Plain Old Data) entities to another, where the two may potentially overlap.

This algorithm has the same semantics as std::copy(), but it uses memmove() to copy elements en bloc, rather than copy assignment of one element at a time.

Note:
The implementation uses static assertions to ensure that the source and destination element types are the same size.

The implementation uses constraints ensure sure that the source and destination element types are POD

Parameters:
first Contiguous Iterator marking the start of the source range
last Contiguous Iterator marking the one-past-the-end of the source range
dest Contiguous Iterator marking the start of the source range

References ss_typename_type_k, stlsoft::std_copy(), and STLSOFT_STATIC_ASSERT.

void stlsoft::pod_move_n ( O *  dest,
I *  src,
size_t  n 
) [inline]

Copies one range of POD (Plain Old Data) entities to another, where the two may potentially overlap.

Note:
This algorithm uses memmove() to copy elements en bloc, rather than copy assignment of one element at a time.

The implementation uses static assertions to ensure that the source and destination element types are the same size.

The implementation uses constraints ensure sure that the source and destination element types are POD

Parameters:
dest Contiguous Iterator marking the start of the source range
src Contiguous Iterator marking the start of the source range
n Number of elements in the range

References ss_typename_type_k, stlsoft::std_copy(), and STLSOFT_STATIC_ASSERT.

void stlsoft::remove_duplicates_from_unordered_sequence ( C &  container  )  [inline]

This algorithm removes duplicate entries from unordered sequences.

It necessarily runs in O(n2) time, since it must do a bubble-like double pass on the sequence (in order to work with unordered sequences).

Parameters:
container The container

References stlsoft::remove_duplicates_from_unordered_sequence(), ss_typename_type_k, and stlsoft_ns_qual_std.

void stlsoft::remove_duplicates_from_unordered_sequence ( C &  container,
BP  pred 
) [inline]

This algorithm removes duplicate entries from unordered sequences.

It necessarily runs in O(n2) time, since it must do a bubble-like double pass on the sequence (in order to work with unordered sequences).

Parameters:
container The container
pred The predicate used to determine the equivalence of items

References ss_typename_type_k, and stlsoft::std_advance().

Referenced by stlsoft::remove_duplicates_from_unordered_sequence().

void stlsoft::replace_n ( src,
size_t  n,
T const &  oldValue,
T const &  newValue 
) [inline]

Copies N elements from the range [src, src + n) to the range [dest, dest + n).

Parameters:
src The iterator copied from
n The number of elements copied
oldValue The value to search for
newValue The value to replace with

References stlsoft::std_replace().

I stlsoft::skip_equal ( first,
last 
) [inline]

Skips along from a given iteration point to the first subsequent iteration point whose value is not equal to that of the starting point.

Parameters:
first The start of the sequence
last The (one past the) end point of the sequence

void stlsoft::sort ( RI  first,
RI  last 
) [inline]

Equivalent to std::sort().

References stlsoft_ns_qual_std.

Referenced by stlsoft::std_sort().

void stlsoft::std_advance ( I &  i,
ss_ptrdiff_t  n 
) [inline]

Equivalent to std::advance().

References stlsoft_ns_qual_std.

Referenced by stlsoft::remove_duplicates_from_unordered_sequence().

O stlsoft::std_copy ( first,
last,
dest 
) [inline]

size_t stlsoft::std_count_if ( first,
last,
UP  pred 
) [inline]

Equivalent to std::count_if().

References stlsoft_ns_qual_std.

Referenced by stlsoft::for_each_count_success().

void stlsoft::std_fill ( first,
last,
V const &  value 
) [inline]

Equivalent to std::fill().

References stlsoft_ns_qual_std.

Referenced by stlsoft::for_each_set_value().

void stlsoft::std_fill_n ( dest,
size_t  n,
V const &  value 
) [inline]

Equivalent to std::fill_n().

References stlsoft_ns_qual_std.

Referenced by stlsoft::pod_fill_n().

I stlsoft::std_find ( first,
last,
V const &  value 
) [inline]

Equivalent to std::find().

References stlsoft_ns_qual_std.

I stlsoft::std_find_if ( first,
last,
UP  pred 
) [inline]

Equivalent to std::find_if().

References stlsoft_ns_qual_std.

UF stlsoft::std_for_each ( first,
last,
UF  func 
) [inline]

Equivalent to std::for_each().

References stlsoft_ns_qual_std.

Referenced by stlsoft::for_all(), and stlsoft::for_all_r().

void stlsoft::std_replace ( first,
last,
T const &  valFind,
T const &  valReplace 
) [inline]

Equivalent to std::replace().

Referenced by stlsoft::replace_n().

void stlsoft::std_sort ( RI  first,
RI  last,
BP  pred 
) [inline]

Equivalent to std::sort().

References stlsoft::sort(), and stlsoft_ns_qual_std.

O stlsoft::std_transform ( first,
last,
dest,
UF  func 
) [inline]

Equivalent to std::transform().

References stlsoft_ns_qual_std.

FI stlsoft::std_unique ( FI  first,
FI  last 
) [inline]

Equivalent to std::unique().

References stlsoft_assert, and stlsoft_ns_qual_std.

FI stlsoft::std_unique ( FI  first,
FI  last,
BP  pred 
) [inline]

Equivalent to std::unique().

References stlsoft_assert, and stlsoft_ns_qual_std.

OI stlsoft::std_unique_copy ( FI  first,
FI  last,
OI  dest,
BP  pred 
) [inline]

Equivalent to std::unique_copy().

References stlsoft_assert, and stlsoft_ns_qual_std.

OI stlsoft::std_unique_copy ( FI  first,
FI  last,
OI  dest 
) [inline]

Equivalent to std::unique_copy().

References stlsoft_assert, and stlsoft_ns_qual_std.

bool stlsoft::unordered_includes ( I1  first1,
I1  last1,
I2  first2,
I2  last2 
) [inline]

Determines whether all elements from the range [first2, last2) are contained within the range [first1, last1).

Note:
The algorithm does not assume that the ranges are ordered, and so does linear searches. If the ranges are ordered, you should use std::includes


Generated on Thu Jun 10 08:58:17 2010 for STLSoft by  doxygen 1.5.6