emlabcpp
modern opinionated embedded C++ library
algorithm.h File Reference
#include "./algorithm/impl.h"
#include "./bounded.h"
#include "./min_max.h"
#include "./range.h"
#include "./types.h"
#include "./view.h"
#include <cmath>
#include <cstdlib>
#include <tuple>
+ Include dependency graph for algorithm.h:

Go to the source code of this file.

Classes

struct  emlabcpp::convert_to< T >
 Object with operator() that constructs object of type Tout of passed-in value. More...
 

Namespaces

 emlabcpp
 MIT License.
 

Functions

template<typename T >
constexpr int emlabcpp::sign (T const &val)
 returns sign of variable T: -1,0,1 More...
 
template<typename T >
constexpr T emlabcpp::ceil_to (T val, T base)
 takes an value val and rounds it up to nearest multiply of base More...
 
template<additive_operators T, arithmetic_operators U>
constexpr U emlabcpp::map_range (T input, T from_min, T from_max, U to_min, U to_max)
 maps input value 'input' from input range to equivalent value in output range More...
 
template<container Container>
constexpr std::size_t emlabcpp::cont_size (Container const &cont) noexcept
 Returns the size of the container, regardless of what it is. More...
 
template<typename T >
constexpr bool emlabcpp::almost_equal (T const &lh, T const &rh, float const eps=default_epsilon)
 Two items 'lh' and 'rh' are almost equal if their difference is smaller than value 'eps'. More...
 
template<referenceable_container Container, typename Iterator = iterator_of_t< Container >>
constexpr view< Iterator > emlabcpp::tail (Container &&cont, int const step=1)
 Returns range over Container, which skips first item of container. More...
 
template<referenceable_container Container, typename Iterator = iterator_of_t< Container >>
constexpr view< Iterator > emlabcpp::init (Container &&cont, int const step=1)
 Returns range over Container, which skips last item of container. More...
 
template<range_container Container, container_invocable< Container > PredicateCallable = std::identity>
constexpr auto emlabcpp::find_if (Container &&cont, PredicateCallable &&f=std::identity())
 Returns iterator for first item, for which call to predicate f(*iter) holds true. More...
 
template<gettable_container Container, container_invocable< Container > PredicateCallable = std::identity>
 emlabcpp::requires (!range_container< Container >) const expr std
 Returns index of an element in tuple 't', for which call to predicate f(x) holds true, otherwise returns index of 'past the end' item - size of the tuple. More...
 
template<container Container, typename T >
constexpr auto emlabcpp::find (Container &&cont, T const &item)
 Finds first item in container 'cont' that is equal to 'item', returns iterator for container, or index for tuples. More...
 
template<container Container, typename T >
constexpr bool emlabcpp::contains (Container const &cont, T const &item)
 Checks if container cont contains at least one occurence of item, returns true/false. More...
 
template<gettable_container Container, container_invocable< Container > UnaryCallable>
 emlabcpp::requires (!range_container< Container >) const expr void for_each(Container &&cont
 Applies unary callable 'f' to each element of container 'cont'. More...
 
template<range_container Container, container_invocable< Container > UnaryCallable>
constexpr void emlabcpp::for_each (Container &&cont, UnaryCallable &&f)
 Applies unary callable 'f' to each element of container 'cont'. More...
 
template<container Container, container_invocable< Container > UnaryCallable = std::identity, typename T = std::decay_t< mapped_t< Container, UnaryCallable > >>
constexpr min_max< T > emlabcpp::min_max_elem (Container &&cont, UnaryCallable &&f=std::identity())
 Applies unary callable 'f(x)' to each element of container 'cont', returns the largest and the smallest return value. More...
 
template<container Container, container_invocable< Container > UnaryCallable = std::identity, typename T = std::decay_t< mapped_t< Container, UnaryCallable > >>
constexpr T emlabcpp::max_elem (Container &&cont, UnaryCallable &&f=std::identity())
 Applies unary callable 'f(x)' to each element of container 'cont', returns the largest return value of 'f(x)' calls. More...
 
template<container Container, container_invocable< Container > UnaryCallable = std::identity, typename T = std::decay_t< mapped_t< Container, UnaryCallable > >>
constexpr T emlabcpp::min_elem (Container &&cont, UnaryCallable &&f=std::identity())
 Applies unary callable 'f(x) to each element of container 'cont‘, returns the smallest return value of 'f(x)’ calls. More...
 
template<container Container, container_invocable< Container > UnaryCallable = std::identity>
constexpr std::size_t emlabcpp::count (Container &&cont, UnaryCallable &&f=std::identity())
 Applies the predicate 'f(x)' to each element of container 'cont' and returns the count of items, for which f(x) returned 'true'. More...
 
template<container Container, container_invocable< Container > UnaryCallable = std::identity, typename T = std::decay_t< mapped_t< Container, UnaryCallable > >>
constexpr T emlabcpp::sum (Container &&cont, UnaryCallable &&f=std::identity(), T init={})
 Applies f(x) to each item of container 'cont', returns the sum of all the return values of each call to 'f(x)' and 'init' item. More...
 
template<container Container, typename T , typename BinaryCallable >
constexpr T emlabcpp::accumulate (Container &&cont, T init, BinaryCallable &&f)
 Applies callable 'f(init,x)' to each element of container 'x' and actual value of 'init' in iteration, returns a result of last application. More...
 
template<container Container, container_invocable< Container > UnaryCallable = std::identity, typename T = std::decay_t< mapped_t< Container, UnaryCallable > >>
constexpr T emlabcpp::avg (Container &&cont, UnaryCallable &&f=std::identity())
 Applies callable 'f(x)' to each element of container 'cont' and returns the average value of each call. More...
 
template<container Container, container_invocable< Container > UnaryCallable = std::identity, typename T = std::decay_t< mapped_t< Container, UnaryCallable > >>
constexpr T emlabcpp::variance (Container &&cont, UnaryCallable &&f=std::identity())
 Applies callable 'f(x)' to each element of container 'cont' and returns the variance of values returned from the call. More...
 
template<container LhContainer, container RhContainer, typename BinaryCallable >
constexpr void emlabcpp::for_cross_joint (LhContainer &&lh_cont, RhContainer &&rh_cont, BinaryCallable &&f)
 Applies binary callable 'f(x,y)' to each combination of items x from lh_cont and y from rh_cont More...
 
template<container Container, container_invocable< Container > PredicateCallable = std::identity>
constexpr bool emlabcpp::any_of (Container &&cont, PredicateCallable &&f=std::identity())
 Returns true if call to predicate 'f(x)' returns true for at least one item x in 'cont'. More...
 
template<container Container, container_invocable< Container > PredicateCallable = std::identity>
constexpr bool emlabcpp::none_of (Container &&cont, PredicateCallable &&f=std::identity())
 Returns true if call to predicate 'f(x)' returns false for all items in 'cont'. More...
 
template<container Container, container_invocable< Container > PredicateCallable = std::identity>
constexpr bool emlabcpp::all_of (Container &&cont, PredicateCallable &&f=std::identity())
 Returns true if call to predicate 'f(x)' returns true for all items in 'cont'. More...
 
template<range_container LhContainer, range_container RhContainer, typename BinaryPredicateCallable = std::equal_to< void >>
constexpr bool emlabcpp::equal (LhContainer &&lh, RhContainer &&rh, BinaryPredicateCallable &&f=std::equal_to< void >{})
 Returns true if containers 'lh' and 'rh' has same size and calls to predicate f - f(lh[i],rh[i]) return true for each item. More...
 
template<impl::map_f_collectable ResultContainer, container Container, container_invocable< Container > UnaryCallable = std::identity>
ResultContainer emlabcpp::map_f (Container &&cont, UnaryCallable &&f=std::identity())
 Calls callable f(x) for each item in container 'cont' (or tuple) and stores result in 'ResultContainer', which is returned. More...
 
template<std::size_t N, range_container Container, container_invocable< Container > UnaryCallable = std::identity, typename T = std::decay_t< mapped_t< Container, UnaryCallable > >>
std::array< T, N > emlabcpp::map_f_to_a (Container &&cont, UnaryCallable &&f=std::identity()) requires(!static_sized< Container >)
 Calls callable f(cont[i]) for i = 0...N and stores the result in array of an size N. More...
 
template<range_container Container, typename T , container_invocable< Container > UnaryCallable = std::identity>
constexpr T emlabcpp::joined (Container &&cont, T const &val, UnaryCallable &&f=std::identity())
 Function applies callable f to each item in container cont and contacts results with operator+, val is used as a separator between the items. More...
 
template<container Container, typename Iterator >
void emlabcpp::copy (Container &&cont, Iterator iter)
 
template<std::size_t N, typename NullCallable >
constexpr void emlabcpp::for_each_index (NullCallable &&f)
 Executes unary callable f() with template argument of type 'std::size_t', which ranges from 0 to N. More...
 
template<std::size_t N, typename PredicateCallable >
constexpr std::size_t emlabcpp::find_if_index (PredicateCallable &&f)
 Executes unary callable f() with template argument of type 'std::size_t', which ranges from 0 to N until first call that returns true. More...
 
template<std::size_t i, typename PredicateCallable >
constexpr bool emlabcpp::until_index (PredicateCallable &&f)
 Executes predicate f() with template argument of type 'std::size_t', which ranges from 0 to i until first call that returns true. More...
 
template<bounded_derived IndexType, typename Callable >
 emlabcpp::requires (!requires(Callable f) { { f.template operator()< 0 >() } -> std::same_as< void >;}) const expr auto select_index(IndexType i
 Function expectes bounded value as index input and callable. More...
 
 emlabcpp::select_index (i, [&res, &f]< std::size_t i >() { res=f.template operator()< i >();})
 
template<bounded_derived IndexType, typename Callable >
requires emlabcpp::requires (Callable f)
 
constexpr void emlabcpp::select_index (IndexType i, Callable &&f)
 
template<typename... Args, std::size_t N = sizeof...( Args )>
constexpr std::array< std::byte, N > emlabcpp::bytes (Args const &... args)
 Conveft the provided arguments into array of std::byte. More...
 
template<typename Arr , typename... Arrs>
constexpr auto emlabcpp::merge_arrays (Arr &&first, Arrs &&... arrs)
 Expects multiple std::arrays on input, and merges all together into one std::array instance. More...
 
template<std::size_t N, typename T >
constexpr std::array< T, N > emlabcpp::filled (T const &item)
 Constructs an array filled with value x More...
 

Variables

constexpr float emlabcpp::default_epsilon = 1.19e-07f
 
UnaryCallable && emlabcpp::f
 
emlabcpp::res {}