|
0.12.0
|
|
Freundlich's C++ toolkit |
General-purpose algorithms that don't really fit into a common category.
Classes | |
| class | fcppt::algorithm::element_not_found |
May be thrown by the _exn algorithms like fcppt::algorithm::find_exn() More... | |
| class | fcppt::algorithm::exception |
| The exception thrown by some algorithm operations. More... | |
Functions | |
| template<typename DestContainer , typename SourceContainer > | |
| void | fcppt::algorithm::append (DestContainer &dest, SourceContainer const &src) |
Appends the sequence src to dest. | |
| template<typename TargetArray , typename SourceArray , typename Functor > | |
| TargetArray const | fcppt::algorithm::array_map (SourceArray const &source, Functor const &f) |
| Applies a functor to an array and returns a new array containing the results. | |
| template<typename In , typename T > | |
| bool | fcppt::algorithm::contains (In const beg, In const end, T const &value) |
Checks if a given value is inside the range [beg,end]. | |
| template<typename Container , typename T > | |
| bool | fcppt::algorithm::contains (Container const &container, T const &value) |
Checks if a given value is inside a range. | |
| template<typename In , typename Pred > | |
| bool | fcppt::algorithm::contains_if (In const beg, In const end, Pred const &pred) |
Checks if a given value matches pred inside the range [beg end]. | |
| template<typename Container , typename Pred > | |
| bool | fcppt::algorithm::contains_if (Container const &container, Pred const &pred) |
Checks if a given value is inside a range. | |
| template<typename InputIterator , typename OutputIterator , typename Predicate > | |
| OutputIterator | fcppt::algorithm::copy_if (InputIterator first, InputIterator last, OutputIterator result, Predicate pred) |
| Assigns the values of elements from a source range satisfying a predicate to a destination range,. | |
| template<typename In , typename Out , typename Size > | |
| Out | fcppt::algorithm::copy_n (In const _beg, Size const _sz, Out const _out) |
Copies sz elements from _beg to _out. | |
| template<typename In , typename T > | |
| In | fcppt::algorithm::find_exn (In const begin, In const end, T const &t) |
| Like std::find but throws fcppt::algorithm::element_not_found. | |
| template<typename In , typename Comp > | |
| In | fcppt::algorithm::find_if_exn (In const begin, In const end, Comp const &comp) |
| Like std::find_if but throws fcppt::algorithm::element_not_found. | |
| template<typename Container > | |
| Container const | fcppt::algorithm::join (Container _left, Container const &_right) |
| Joins two containers. | |
| template<typename Range > | |
| Range::value_type const | fcppt::algorithm::join_strings (Range const &_range, typename Range::value_type const &_delim) |
Joins a range of items delimited by delim. | |
| template<typename Range > | |
| boost::range_size< Range >::type | fcppt::algorithm::levenshtein (Range const &source, Range const &target) |
| Calculates the Levenshtein distance. | |
| template<typename TargetContainer , typename SourceContainer , typename Functor > | |
| TargetContainer const | fcppt::algorithm::map (SourceContainer const &s, Functor const &f) |
| Transforms a container using a functor to another container. | |
| template<typename Container , typename Ptr > | |
| boost::enable_if < boost::is_same< typename boost::add_pointer< typename boost::remove_const< typename boost::remove_pointer< Ptr > ::type >::type >::type, typename Container::value_type > , bool >::type | fcppt::algorithm::ptr_container_erase (Container &_container, Ptr const _element) |
Removes pointer _element from the ptr_container _container. | |
| template<typename Container , typename Predicate > | |
| bool | fcppt::algorithm::ptr_container_erase_if (Container &_container, Predicate const &_predicate) |
Removes pointer from the ptr_container _container if _predicate matches. | |
| template<typename Container > | |
| bool | fcppt::algorithm::remove (Container &_container, typename Container::const_reference _element) |
Tries to remove all elements from _container matching _element. | |
| template<typename Container , typename Predicate > | |
| bool | fcppt::algorithm::remove_if (Container &_container, Predicate const &_predicate) |
Tries to remove all elements from _container matching _predicate. | |
| template<typename Set > | |
| Set const | fcppt::algorithm::set_intersection (Set const &a, Set const &b) |
| Calculates the intersection of two sets. | |
| template<typename Container1 , typename Container2 , typename Equality > | |
| bool | fcppt::algorithm::shift_compare (Container1 const &a, Container2 b, Equality const &is_equal) |
Tests if a is equal b up to rotation. | |
| void fcppt::algorithm::append | ( | DestContainer & | dest, |
| SourceContainer const & | src | ||
| ) |
Appends the sequence src to dest.
| DestContainer | Must have an insert function taking three integers (like the std containers all do). |
| SourceContainer | Must have a begin and end member function. |
Example:
| TargetArray const fcppt::algorithm::array_map | ( | SourceArray const & | source, |
| Functor const & | f | ||
| ) |
Applies a functor to an array and returns a new array containing the results.
| TargetArray | Must be default-constructible |
Example:
| bool fcppt::algorithm::contains | ( | In const | beg, |
| In const | end, | ||
| T const & | value | ||
| ) |
Checks if a given value is inside the range [beg,end].
| In | A forward iterator |
| T | A type compatible with the iterator's value type |
This is equivalent to
| bool fcppt::algorithm::contains | ( | Container const & | container, |
| T const & | value | ||
| ) |
Checks if a given value is inside a range.
| In | A container type having begin and end member functions |
| T | The container's value type |
This is equivalent to
| bool fcppt::algorithm::contains_if | ( | In const | beg, |
| In const | end, | ||
| Pred const & | pred | ||
| ) |
Checks if a given value matches pred inside the range [beg end].
| In | A forward iterator |
| Pred | A predicate (a unary function returning a bool) |
This is equivalent to
| bool fcppt::algorithm::contains_if | ( | Container const & | container, |
| Pred const & | pred | ||
| ) |
Checks if a given value is inside a range.
| In | A container type having begin and end member functions |
| Pred | A predicate (a unary function returning a bool) |
This is equivalent to
This is equivalent to
| OutputIterator fcppt::algorithm::copy_if | ( | InputIterator | first, |
| InputIterator | last, | ||
| OutputIterator | result, | ||
| Predicate | pred | ||
| ) |
Assigns the values of elements from a source range satisfying a predicate to a destination range,.
| InputIterator | An input iterator type |
| OutputIterator | An output iterator type |
| Predicate | An unary predicate |
| first | An input iterator addressing the position of the first element in the source range. |
| last | An input iterator addressing the position that is one past the final element in the source range. |
| result | An output iterator addressing the position of the first element in the destination range. |
| pred | User-defined predicate function object that defines the condition to be satisfied if an element is to be counted. A predicate takes single argument and returns true or false. |
The C++03's standard library is missing this function. C++11 includes it in the standard library, but for compatibility, you can use fcppt's version.
| Out fcppt::algorithm::copy_n | ( | In const | _beg, |
| Size const | _sz, | ||
| Out const | _out | ||
| ) |
Copies sz elements from _beg to _out.
Equivalent to
std::copy(_beg, _beg + _sz, _out)
| In fcppt::algorithm::find_exn | ( | In const | begin, |
| In const | end, | ||
| T const & | t | ||
| ) |
Like std::find but throws fcppt::algorithm::element_not_found.
| fcppt::algorithm::element_not_found | If the element was not found |
| In fcppt::algorithm::find_if_exn | ( | In const | begin, |
| In const | end, | ||
| Comp const & | comp | ||
| ) |
Like std::find_if but throws fcppt::algorithm::element_not_found.
| fcppt::algorithm::element_not_found | If the element was not found |
| Container const fcppt::algorithm::join | ( | Container | _left, |
| Container const & | _right | ||
| ) |
Joins two containers.
Joins containers _left and _right, by inserting _right into _left.
| _left | The left container |
| _right | The right container, which will be inserted into the left container |
| Container | A container class that supports insert of iterator ranges |
| Range::value_type const fcppt::algorithm::join_strings | ( | Range const & | _range, |
| typename Range::value_type const & | _delim | ||
| ) |
Joins a range of items delimited by delim.
| _range | A forward-iterable range. The range's value_type must have an operator+= |
| _delim | The delimiting value |
Example:
| boost::range_size<Range>::type fcppt::algorithm::levenshtein | ( | Range const & | source, |
| Range const & | target | ||
| ) |
Calculates the Levenshtein distance.
See http://en.wikipedia.org/wiki/Levenshtein_distance for an explanation of the algorithm.
Range::size_type and Range::value_type exist bool Range::empty() const exists size_type Range::size() const exists Range::operator[] exists Range::value_type has to have an operator== | TargetContainer const fcppt::algorithm::map | ( | SourceContainer const & | s, |
| Functor const & | f | ||
| ) |
Transforms a container using a functor to another container.
| TargetContainer | Must be default-constructible |
This is equivalent to:
std::transform(source.begin(),source.end(),inserter,f)
with an appropriate inserter.
| boost::enable_if< boost::is_same< typename boost::add_pointer< typename boost::remove_const< typename boost::remove_pointer< Ptr >::type >::type >::type, typename Container::value_type >, bool>::type fcppt::algorithm::ptr_container_erase | ( | Container & | _container, |
| Ptr const | _element | ||
| ) |
Removes pointer _element from the ptr_container _container.
| Ptr | May be Container::value_type or a const version of it |
true if the element was found/erased, false otherwise | bool fcppt::algorithm::ptr_container_erase_if | ( | Container & | _container, |
| Predicate const & | _predicate | ||
| ) |
Removes pointer from the ptr_container _container if _predicate matches.
true if the element was found/erased, false otherwiseThis is different from the erase_if member functions because it returns if something has been erased.
| bool fcppt::algorithm::remove | ( | Container & | _container, |
| typename Container::const_reference | _element | ||
| ) |
Tries to remove all elements from _container matching _element.
| bool fcppt::algorithm::remove_if | ( | Container & | _container, |
| Predicate const & | _predicate | ||
| ) |
Tries to remove all elements from _container matching _predicate.
true if something has been removed, false otherwise | Set const fcppt::algorithm::set_intersection | ( | Set const & | a, |
| Set const & | b | ||
| ) |
Calculates the intersection of two sets.
| Set | Must be default-constructible |
This just calls std::set_intersection writes the result to a new container. </pre
| bool fcppt::algorithm::shift_compare | ( | Container1 const & | a, |
| Container2 | b, | ||
| Equality const & | is_equal | ||
| ) |
Tests if a is equal b up to rotation.
Container1::value_type and Container2::value_type have to be equality-comparable.Example:
1.8.2