libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
algorithm.h File Reference
#include <algorithm>
#include <numeric>
#include <functional>
#include <promeki/core/namespace.h>
#include <promeki/core/list.h>
Include dependency graph for algorithm.h:

Go to the source code of this file.

Functions

template<typename Container >
PROMEKI_NAMESPACE_BEGIN Container sorted (Container c)
 Returns a sorted copy of the container.
 
template<typename Container , typename Compare >
Container sorted (Container c, Compare comp)
 Returns a sorted copy of the container using a custom comparator.
 
template<typename Container , typename Predicate >
Container filtered (const Container &c, Predicate pred)
 Returns a copy of the container with only elements matching the predicate.
 
template<typename Container , typename Transform >
auto mapped (const Container &c, Transform fn)
 Returns a container of transformed elements.
 
template<typename Container , typename Predicate >
bool allOf (const Container &c, Predicate pred)
 Returns true if all elements satisfy the predicate.
 
template<typename Container , typename Predicate >
bool anyOf (const Container &c, Predicate pred)
 Returns true if any element satisfies the predicate.
 
template<typename Container , typename Predicate >
bool noneOf (const Container &c, Predicate pred)
 Returns true if no elements satisfy the predicate.
 
template<typename Container , typename Callable >
void forEach (const Container &c, Callable fn)
 Applies a callable to each element.
 
template<typename Container , typename Init , typename BinaryOp >
Init accumulate (const Container &c, Init init, BinaryOp op)
 Folds/reduces the container with a binary operation.
 
template<typename Container >
auto minElement (const Container &c)
 Returns an iterator to the minimum element.
 
template<typename Container >
auto maxElement (const Container &c)
 Returns an iterator to the maximum element.
 
template<typename Container , typename Value >
bool contains (const Container &c, const Value &val)
 Returns true if the container contains the given value.
 

Detailed Description

See LICENSE file in the project root folder for license information.

Function Documentation

◆ accumulate()

Init accumulate ( const Container c,
Init  init,
BinaryOp  op 
)

Folds/reduces the container with a binary operation.

Template Parameters
ContainerA container with begin()/end().
InitThe accumulator initial value type.
BinaryOpA binary operation.
Parameters
cThe container.
initThe initial value.
opThe binary operation.
Returns
The accumulated result.

◆ allOf()

bool allOf ( const Container c,
Predicate  pred 
)

Returns true if all elements satisfy the predicate.

Template Parameters
ContainerA container with begin()/end().
PredicateA unary predicate.
Parameters
cThe container.
predThe predicate.
Returns
True if all elements match.

◆ anyOf()

bool anyOf ( const Container c,
Predicate  pred 
)

Returns true if any element satisfies the predicate.

Template Parameters
ContainerA container with begin()/end().
PredicateA unary predicate.
Parameters
cThe container.
predThe predicate.
Returns
True if any element matches.

◆ contains()

template<typename Container , typename Value >
bool contains ( const Container c,
const Value &  val 
)

Returns true if the container contains the given value.

Template Parameters
ContainerA container with begin()/end().
ValueThe value type.
Parameters
cThe container.
valThe value to search for.
Returns
True if found.

◆ filtered()

Container filtered ( const Container c,
Predicate  pred 
)

Returns a copy of the container with only elements matching the predicate.

Template Parameters
ContainerA container with begin()/end().
PredicateA unary predicate.
Parameters
cThe source container.
predThe predicate.
Returns
A filtered copy.

◆ forEach()

void forEach ( const Container c,
Callable  fn 
)

Applies a callable to each element.

Template Parameters
ContainerA container with begin()/end().
CallableA unary function.
Parameters
cThe container.
fnThe function to apply.

◆ mapped()

auto mapped ( const Container c,
Transform  fn 
)

Returns a container of transformed elements.

Template Parameters
ContainerA container with begin()/end() and a value_type.
TransformA unary transformation function.
Parameters
cThe source container.
fnThe transform function.
Returns
A List of transformed values.

◆ maxElement()

template<typename Container >
auto maxElement ( const Container c)

Returns an iterator to the maximum element.

Template Parameters
ContainerA container with begin()/end().
Parameters
cThe container.
Returns
Iterator to the maximum element.

◆ minElement()

template<typename Container >
auto minElement ( const Container c)

Returns an iterator to the minimum element.

Template Parameters
ContainerA container with begin()/end().
Parameters
cThe container.
Returns
Iterator to the minimum element.

◆ noneOf()

bool noneOf ( const Container c,
Predicate  pred 
)

Returns true if no elements satisfy the predicate.

Template Parameters
ContainerA container with begin()/end().
PredicateA unary predicate.
Parameters
cThe container.
predThe predicate.
Returns
True if no elements match.

◆ sorted()

Container sorted ( Container  c,
Compare  comp 
)

Returns a sorted copy of the container using a custom comparator.

Template Parameters
ContainerA container with begin()/end() and a copy constructor.
CompareA binary comparison function.
Parameters
cThe source container.
compThe comparator.
Returns
A sorted copy.