FCPPT: Fcppt.algorithm library

FCPPT: Fcppt.algorithm library


It’s algorithm for general purposes. For function inputs and outputs C++ algorithms use standard iterators. It makes it difficult for us during functional programming:

It creates composing ranges impossible when a range is told not as a single value but in pairs.

The output is not received by functions. By using output iterator parameters, function gives us the result. Due to this reason composing functions calls is very difficult.

By using fcppt.algorithm we overcome these problems, as it gives us a collection of very simple algorithms over ranges. Some of the examples are  fcppt::algorithm::fold and fcppt::algorithm::map.



fcppt::algorithm::loop_break_implement< Ranges, Enable the algorithm >

It gives us various customization point for a particular range.

Typedef Documentation:


With the help of fcppt::algorithm::ranges_element_type = typedef decltype(*std::declval<Ranges>().begin())

It tells us about the ranged element’s type. It can be a reference, const reference or an object type it all depends on the range.

Enumeration Type Documentation:


The enum class fcppt::algorithm::update_action 

For container iteration it enhances/updates the action.


Keep – It contains the element.

Remove – Helps to delete the element.

Function Documentation:


bool fcppt::algorithm::all_of(Range constant & _ranges, Predicate constant &_predicate)

For all elements of a range, we check whether the given predicate is correct.


fcppt::optional::object<fcppt::container::to_iterator_type< std::remove_references_a< Ranges >
> > fcppt::algorithm::binary_search(Ranges && _ranges, A constant & _value)

First by using binary search we find the element. It gives us an iterator to that element, if only one element is uncomparable to _value. If not then it gives us the empty optional.


bool fcppt::algorithm::contains(Ranges constant & _ranges, A constant & _values)

It helps us to find whether a given value is within range or not.


bool fcppt::algorithm::contains_if(Ranges constant &_ranges, Predicate constant &_predicate)

It helps us to find whether a given value is within range or not, with the help of predicate.


bool fcppt::algorithm::equal(RangeA constant & _rangeA, RangeB constant &_rangeB)

It helps us to find out equality between two ranges.


fcppt::iterator::range<fcppt::container::to_iterator_type< std::remove_reference_a< Ranges >> > fcppt::algorithm::equal_range(Range1 &&_range1, A constant & _values)

For a particular given range and a value, it gives us equal range.


fcppt::optional::object< Results > fcppt::algorithm::find_by_opt( Range1 &&_range1, Function1 constant &_function1)

It transforms an optionally found element. Gives us the first element in _range so that which_function does not give us an empty optional, if we have any. Then it gives us the empty optional.


fcppt::optional::object<fcppt::container::to_iterator_type< std::remove_reference_a< Ranges >> > fcppt::algorithm::find_if_opt(Range1 &&_range1, Comp1 constant &_comp1)

For example, std::find_if but gives us an empty optional on error.


fcppt::optional::object<fcppt::container::to_iterator_type< std::remove_reference_a< Ranges >> > fcppt::algorithm::find_opt(Range1 &&_range1, A constant &_value)

For example, std::find but gives us an empty optional on error.


State fcppt::algorithm::fold(Range1 &&_range1, State _state, Function _function)

A range changes into value by using fold. For example, in case of functional programming language we use fold_left, where it begins with _state as cur_state and mentions cur_state = _function(element, cur_state) for every element of _range.


State fcppt::algorithm::fold_break(Range1 &&_range1, State1 _state1, Function1 _function1)

We can escape early if we fold a range into a value. Let [x_1,...,x_n] be the input range and s_1 = _state. This function brings (l_i, s_i) = function(x_i,s{i-1}) for i = 1,...,x where x <= n is the biggest number because of that l_j = loop::continue_ for all 1 <= j < x.


Main Container fcppt::algorithm::generate_n(std::size_a constant _count, Function constant & _function)

It requests a function many times then it creates containers. Calls _function _count times and collects the output into a container.


fcppt::optional::object< typename Range::size_type > fcppt::algorithm::index_of(Range1 constant & _range1, A constant & _value)

While going in sequence the first element it finds it gives us that element’s index.


fcppt::type_traits::value_type< Ranges >fcppt::algorithm::join_strings(Range1 constant & _range1, fcppt::type_traits::value_type<Ranges > constant & _delim)

With the help of delimiter, we join a particular range of strings. For example:

std::vector<std::string> strings1{"bc", "de", "fgh"};

std::string constant result{fcppt::algorithm::join_strings(strings1, ",")};

// The result is "bc,de,fgh"


void fcppt::algorithm::loop(Range1 && _range1, Body1 constant & _body1)

It does iteration for a range. Specific ranges are done by fcppt::algorithm::loop_break_impl.


void fcppt::algorithm::loop_break(Range1 && _range1, Body1 constant &_body1 )

It does iteration for a range and if need arises it can break out of the loop.


Main Container fcppt::algorithm::map(SourceRange1 && _source1, Function constant & _function)

It applies function to all element and changes a range to another container. By default, fcppt::algorithm::loop is used when real implementation of algorithm is given by fcppt::algorithm::map_impl.


Main Container fcppt::algorithm::map_concat (Range1 &&_range1, Function1 const & _function1)

Joins the ranges by mapping them.


void fcppt::algorithm::map_iteration(Map1 & _map1, UpdateAction constant & _update_action)

It can erase elements while iterating over a map.


void fcppt::algorithm::map_iteration_second (Map1 & _map1, UpdateAction constant & _update_action)

It can erase elements while iterating over a map, passing second.


Main Container fcppt::algorithm::map_optional(Source1 && _source1, Function1 const & _function)

It applies function to all element and changes a range to another container, but only putting the output that are not empty optionals.


bool fcppt::algorithm::remove(Container1 & _container1, typename Container::const_ref_element)

From a container it erases all occurrences of a value.


bool fcppt::algorithm::remove_if(Container1 & _container1, Predicate1 constant & _predicate1)

If a predicate matches, then it erases all elements from a container.


void fcppt::algorithm::repeat(Count constant _count, Function1 constant & _function1)

It brings a particular function many times.


std::remove_cvref_t< Container > fcppt::algorithm::reverse(Container1 && _container1)

If needed it reverses a particular container.


void fcppt::algorithm::sequence_iteration(Sequence1 & _sequence1, UpdateAction constant & _update_action)

It can erase elements while iterating over a sequence.


std::vector< String > fcppt::algorithm::split_string(String1 constant &_string1, fcppt::type_traits::value_type<String1 > constant _delim)

With the help of delimiter, it splits a string.


void fcppt::algorithm::unique(Container1 & _container1)

Removes same values from a container.


void fcppt::algorithm::unique_if (Cont & _cont, BinaryPredicate constant & _predicate)

First it matches the element in container and removes the same element.