Pigweed
C/C++ API Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Namespaces | Functions
algorithm.h File Reference
#include <algorithm>
#include <utility>
#include "pw_containers/internal/algorithm_internal.h"

Go to the source code of this file.

Namespaces

namespace  pw
 Provides basic helpers for reading and writing UTF-8 encoded strings.
 

Functions

template<typename C , typename Pred >
bool pw::containers::AllOf (const C &c, Pred &&pred)
 
template<typename C , typename Pred >
bool pw::containers::AnyOf (const C &c, Pred &&pred)
 
template<typename C , typename Pred >
bool pw::containers::NoneOf (const C &c, Pred &&pred)
 
template<typename C , typename Function >
std::decay_t< Function > pw::containers::ForEach (C &&c, Function &&f)
 
template<typename C , typename T >
internal_algorithm::ContainerIter< C > pw::containers::Find (C &c, T &&value)
 
template<typename C , typename Pred >
internal_algorithm::ContainerIter< C > pw::containers::FindIf (C &c, Pred &&pred)
 
template<typename C , typename Pred >
internal_algorithm::ContainerIter< C > pw::containers::FindIfNot (C &c, Pred &&pred)
 
template<typename Sequence1 , typename Sequence2 >
internal_algorithm::ContainerIter< Sequence1 > pw::containers::FindEnd (Sequence1 &sequence, Sequence2 &subsequence)
 
template<typename Sequence1 , typename Sequence2 , typename BinaryPredicate >
internal_algorithm::ContainerIter< Sequence1 > pw::containers::FindEnd (Sequence1 &sequence, Sequence2 &subsequence, BinaryPredicate &&pred)
 
template<typename C1 , typename C2 >
internal_algorithm::ContainerIter< C1 > pw::containers::FindFirstOf (C1 &container, C2 &options)
 
template<typename C1 , typename C2 , typename BinaryPredicate >
internal_algorithm::ContainerIter< C1 > pw::containers::FindFirstOf (C1 &container, C2 &options, BinaryPredicate &&pred)
 
template<typename Sequence >
internal_algorithm::ContainerIter< Sequence > pw::containers::AdjacentFind (Sequence &sequence)
 
template<typename Sequence , typename BinaryPredicate >
internal_algorithm::ContainerIter< Sequence > pw::containers::AdjacentFind (Sequence &sequence, BinaryPredicate &&pred)
 
template<typename C , typename T >
internal_algorithm::ContainerDifferenceType< const C > pw::containers::Count (const C &c, T &&value)
 
template<typename C , typename Pred >
internal_algorithm::ContainerDifferenceType< const C > pw::containers::CountIf (const C &c, Pred &&pred)
 
template<typename C1 , typename C2 >
internal_algorithm::ContainerIterPairType< C1, C2 > pw::containers::Mismatch (C1 &c1, C2 &c2)
 
template<typename C1 , typename C2 , typename BinaryPredicate >
internal_algorithm::ContainerIterPairType< C1, C2 > pw::containers::Mismatch (C1 &c1, C2 &c2, BinaryPredicate pred)
 
template<typename C1 , typename C2 >
bool pw::containers::Equal (const C1 &c1, const C2 &c2)
 
template<typename C1 , typename C2 , typename BinaryPredicate >
bool pw::containers::Equal (const C1 &c1, const C2 &c2, BinaryPredicate &&pred)
 
template<typename C1 , typename C2 >
bool pw::containers::IsPermutation (const C1 &c1, const C2 &c2)
 
template<typename C1 , typename C2 , typename BinaryPredicate >
bool pw::containers::IsPermutation (const C1 &c1, const C2 &c2, BinaryPredicate &&pred)
 
template<typename Sequence1 , typename Sequence2 >
internal_algorithm::ContainerIter< Sequence1 > pw::containers::Search (Sequence1 &sequence, Sequence2 &subsequence)
 
template<typename Sequence1 , typename Sequence2 , typename BinaryPredicate >
internal_algorithm::ContainerIter< Sequence1 > pw::containers::Search (Sequence1 &sequence, Sequence2 &subsequence, BinaryPredicate &&pred)
 
template<typename Sequence , typename Size , typename T >
internal_algorithm::ContainerIter< Sequence > pw::containers::SearchN (Sequence &sequence, Size count, T &&value)
 
template<typename Sequence , typename Size , typename T , typename BinaryPredicate >
internal_algorithm::ContainerIter< Sequence > pw::containers::SearchN (Sequence &sequence, Size count, T &&value, BinaryPredicate &&pred)
 
template<typename InputIt , typename Predicate >
constexpr bool pw::all_of (InputIt first, InputIt last, Predicate pred)
 
template<typename InputIt , typename Predicate >
constexpr bool pw::any_of (InputIt first, InputIt last, Predicate pred)
 
template<typename InputIt , typename Predicate >
constexpr InputIt pw::find_if (InputIt first, InputIt last, Predicate pred)
 

Detailed Description

This header file provides container-based versions of algorithmic functions within the C++ standard library, based on pw_containers. The following standard library sets of functions are covered within this file:

The standard library functions operate on iterator ranges; the functions within this API operate on containers, though many return iterator ranges.

All functions within this API are CamelCase instead of their std:: snake_case counterparts. Calls such as pw::containers::Foo(container, ...) are equivalent to std:: functions such as std::foo(std::begin(cont), std::end(cont), ...). Functions that act on iterators but not conceptually on iterator ranges (e.g. std::iter_swap)

Function Documentation

◆ AdjacentFind() [1/2]

template<typename Sequence >
internal_algorithm::ContainerIter< Sequence > pw::containers::AdjacentFind ( Sequence &  sequence)

Container-based version of the <algorithm> std::adjacent_find() function to find equal adjacent elements within a container.

◆ AdjacentFind() [2/2]

template<typename Sequence , typename BinaryPredicate >
internal_algorithm::ContainerIter< Sequence > pw::containers::AdjacentFind ( Sequence &  sequence,
BinaryPredicate &&  pred 
)

Overload of AdjacentFind() for using a predicate evaluation other than == as the function's test condition.

◆ AllOf()

template<typename C , typename Pred >
bool pw::containers::AllOf ( const C &  c,
Pred &&  pred 
)

Container-based version of the <algorithm> std::all_of() function to test if all elements within a container satisfy a condition.

◆ AnyOf()

template<typename C , typename Pred >
bool pw::containers::AnyOf ( const C &  c,
Pred &&  pred 
)

Container-based version of the <algorithm> std::any_of() function to test if any element in a container fulfills a condition.

◆ Count()

template<typename C , typename T >
internal_algorithm::ContainerDifferenceType< const C > pw::containers::Count ( const C &  c,
T &&  value 
)

Container-based version of the <algorithm> std::count() function to count values that match within a container.

◆ CountIf()

template<typename C , typename Pred >
internal_algorithm::ContainerDifferenceType< const C > pw::containers::CountIf ( const C &  c,
Pred &&  pred 
)

Container-based version of the <algorithm> std::count_if() function to count values matching a condition within a container.

◆ Equal() [1/2]

template<typename C1 , typename C2 >
bool pw::containers::Equal ( const C1 &  c1,
const C2 &  c2 
)

Container-based version of the <algorithm> std::equal() function to test whether two containers are equal.

Note
The semantics of Equal() are slightly different than those of std::equal(). While the latter iterates over the second container only up to the size of the first container, Equal() also checks whether the container sizes are equal. This better matches expectations about Equal() based on its signature.
vector v1 = <1, 2, 3>;
vector v2 = <1, 2, 3, 4>;
EXPECT_TRUE(equal(std::begin(v1), std::end(v1), std::begin(v2)));
EXPECT_FALSE(Equal(v1, v2));

◆ Equal() [2/2]

template<typename C1 , typename C2 , typename BinaryPredicate >
bool pw::containers::Equal ( const C1 &  c1,
const C2 &  c2,
BinaryPredicate &&  pred 
)

Overload of Equal() for using a predicate evaluation other than == as the function's test condition.

◆ Find()

template<typename C , typename T >
internal_algorithm::ContainerIter< C > pw::containers::Find ( C &  c,
T &&  value 
)

Container-based version of the <algorithm> std::find() function to find the first element containing the passed value within a container value.

◆ FindEnd() [1/2]

template<typename Sequence1 , typename Sequence2 >
internal_algorithm::ContainerIter< Sequence1 > pw::containers::FindEnd ( Sequence1 &  sequence,
Sequence2 &  subsequence 
)

Container-based version of the <algorithm> std::find_end() function to find the last subsequence within a container.

◆ FindEnd() [2/2]

template<typename Sequence1 , typename Sequence2 , typename BinaryPredicate >
internal_algorithm::ContainerIter< Sequence1 > pw::containers::FindEnd ( Sequence1 &  sequence,
Sequence2 &  subsequence,
BinaryPredicate &&  pred 
)

Overload of FindEnd() for using a predicate evaluation other than == as the function's test condition.

◆ FindFirstOf() [1/2]

template<typename C1 , typename C2 >
internal_algorithm::ContainerIter< C1 > pw::containers::FindFirstOf ( C1 &  container,
C2 &  options 
)

Container-based version of the <algorithm> std::find_first_of() function to find the first element within the container that is also within the options container.

◆ FindFirstOf() [2/2]

template<typename C1 , typename C2 , typename BinaryPredicate >
internal_algorithm::ContainerIter< C1 > pw::containers::FindFirstOf ( C1 &  container,
C2 &  options,
BinaryPredicate &&  pred 
)

Overload of FindFirstOf() for using a predicate evaluation other than == as the function's test condition.

◆ FindIf()

template<typename C , typename Pred >
internal_algorithm::ContainerIter< C > pw::containers::FindIf ( C &  c,
Pred &&  pred 
)

Container-based version of the <algorithm> std::find_if() function to find the first element in a container matching the given condition.

◆ FindIfNot()

template<typename C , typename Pred >
internal_algorithm::ContainerIter< C > pw::containers::FindIfNot ( C &  c,
Pred &&  pred 
)

Container-based version of the <algorithm> std::find_if_not() function to find the first element in a container not matching the given condition.

◆ ForEach()

template<typename C , typename Function >
std::decay_t< Function > pw::containers::ForEach ( C &&  c,
Function &&  f 
)

Container-based version of the <algorithm> std::for_each() function to apply a function to a container's elements.

◆ IsPermutation() [1/2]

template<typename C1 , typename C2 >
bool pw::containers::IsPermutation ( const C1 &  c1,
const C2 &  c2 
)

Container-based version of the <algorithm> std::is_permutation() function to test whether a container is a permutation of another.`

◆ IsPermutation() [2/2]

template<typename C1 , typename C2 , typename BinaryPredicate >
bool pw::containers::IsPermutation ( const C1 &  c1,
const C2 &  c2,
BinaryPredicate &&  pred 
)

Overload of IsPermutation() for using a predicate evaluation other than == as the function's test condition.

◆ Mismatch() [1/2]

template<typename C1 , typename C2 >
internal_algorithm::ContainerIterPairType< C1, C2 > pw::containers::Mismatch ( C1 &  c1,
C2 &  c2 
)

Container-based version of the <algorithm> std::mismatch() function to return the first element where two ordered containers differ. Applies == to the first N elements of c1 and c2, where N = min(size(c1), size(c2)).

◆ Mismatch() [2/2]

template<typename C1 , typename C2 , typename BinaryPredicate >
internal_algorithm::ContainerIterPairType< C1, C2 > pw::containers::Mismatch ( C1 &  c1,
C2 &  c2,
BinaryPredicate  pred 
)

Overload of Mismatch() for using a predicate evaluation other than == as the function's test condition. Applies predto the first N elements of c1 and c2, where N = min(size(c1), size(c2)).

◆ NoneOf()

template<typename C , typename Pred >
bool pw::containers::NoneOf ( const C &  c,
Pred &&  pred 
)

Container-based version of the <algorithm> std::none_of() function to test if no elements in a container fulfill a condition.

◆ Search() [1/2]

template<typename Sequence1 , typename Sequence2 >
internal_algorithm::ContainerIter< Sequence1 > pw::containers::Search ( Sequence1 &  sequence,
Sequence2 &  subsequence 
)

Container-based version of the <algorithm> std::search() function to search a container for a subsequence.

◆ Search() [2/2]

template<typename Sequence1 , typename Sequence2 , typename BinaryPredicate >
internal_algorithm::ContainerIter< Sequence1 > pw::containers::Search ( Sequence1 &  sequence,
Sequence2 &  subsequence,
BinaryPredicate &&  pred 
)

Overload of Search() for using a predicate evaluation other than == as the function's test condition.

◆ SearchN() [1/2]

template<typename Sequence , typename Size , typename T >
internal_algorithm::ContainerIter< Sequence > pw::containers::SearchN ( Sequence &  sequence,
Size  count,
T &&  value 
)

Container-based version of the <algorithm> std::search_n() function to search a container for the first sequence of N elements.

◆ SearchN() [2/2]

template<typename Sequence , typename Size , typename T , typename BinaryPredicate >
internal_algorithm::ContainerIter< Sequence > pw::containers::SearchN ( Sequence &  sequence,
Size  count,
T &&  value,
BinaryPredicate &&  pred 
)

Overload of SearchN() for using a predicate evaluation other than == as the function's test condition.