swift
Loading...
Searching...
No Matches
swift::misc::CRangeBase< Derived > Class Template Reference

Any container class with begin and end iterators can inherit from this CRTP class to gain some useful algorithms as member functions. More...

#include <range.h>

Inheritance diagram for swift::misc::CRangeBase< Derived >:
[legend]

Public Member Functions

template<class F>
auto transform (F function) const
 Return a new container generated by applying some transformation function to all elements of this one.
template<class Predicate>
auto findBy (Predicate p) const
 Return a copy containing only those elements for which a given predicate returns true.
template<class K0, class V0, class... KeysValues>
auto findBy (K0 k0, V0 v0, KeysValues... keysValues) const
 Return a copy containing only those elements matching some particular key/value pair(s).
template<class Predicate>
const auto & findFirstBy (Predicate p) const
 Return a reference to the first element for which a given predicate returns true. Undefined if there is none.
template<class K, class V>
const auto & findFirstBy (K key, V value) const
 Return a reference to the first element matching some particular key/value pair(s). Undefined if there is none.
template<class Predicate, class Value>
auto findFirstByOrDefault (Predicate p, const Value &def) const
 Return a copy of the first element for which a given predicate returns true, or a default value if there is none.
template<class Predicate>
auto findFirstByOrDefault (Predicate p) const
 Return a copy of the first element for which a given predicate returns true, or a default value if there is none.
template<class K, class V, class Value>
auto findFirstByOrDefault (K key, V value, const Value &def) const
 Return a copy of the first element matching some particular key/value pair(s), or a default value if there is none.
template<class T, class K, class V>
auto findFirstByOrDefault (K T::*key, V value) const
 Return a copy of the first element matching some particular key/value pair(s), or a default value if there is none.
template<class Predicate>
bool containsBy (Predicate p) const
 Return true if there is an element for which a given predicate returns true.
template<class T>
bool contains (const T &object) const
 Return true if there is an element equal to given object. Uses the most efficient implementation available in the derived container.
template<class K0, class V0, class... KeysValues>
bool contains (K0 k0, V0 v0, KeysValues... keysValues) const
 Return a copy containing only those elements matching some particular key/value pair(s).
template<class T, class Predicate>
bool equalsBy (const T &other, Predicate c) const
 Return true if this container equals another container according to the given element equality predicate.
template<class T, class Key0, class... Keys>
bool equalsByKeys (const T &other, Key0 k0, Keys... keys) const
 Return true if this container equals another container, considering only the given element members.
template<class T>
T randomElement () const
 Pick one random element.
Derived randomElements (int n) const
 Copy n elements from the container at random.
Derived sampleElements (int n) const
 Copy n elements from the container, randomly selected but evenly distributed.

Static Protected Member Functions

template<typename T, typename U>
static bool equalPointers (const T *a, const U *b)
 Efficiently compare addresses of two objects. Return false if types are not compatible.

Detailed Description

template<class Derived>
class swift::misc::CRangeBase< Derived >

Any container class with begin and end iterators can inherit from this CRTP class to gain some useful algorithms as member functions.

Template Parameters
DerivedThe most derived container class inheriting from this instantiation.

Definition at line 32 of file range.h.

Member Function Documentation

◆ contains() [1/2]

template<class Derived>
template<class T>
bool swift::misc::CRangeBase< Derived >::contains ( const T & object) const
inline

Return true if there is an element equal to given object. Uses the most efficient implementation available in the derived container.

Definition at line 109 of file range.h.

◆ contains() [2/2]

template<class Derived>
template<class K0, class V0, class... KeysValues>
bool swift::misc::CRangeBase< Derived >::contains ( K0 k0,
V0 v0,
KeysValues... keysValues ) const
inline

Return a copy containing only those elements matching some particular key/value pair(s).

Parameters
k0A pointer to a member function of T.
v0A value to compare against the value returned by k0.
keysValuesZero or more additional pairs of { pointer to member function of T, value to compare it against }.

Definition at line 120 of file range.h.

◆ containsBy()

template<class Derived>
template<class Predicate>
bool swift::misc::CRangeBase< Derived >::containsBy ( Predicate p) const
inline

Return true if there is an element for which a given predicate returns true.

Definition at line 101 of file range.h.

◆ equalPointers()

template<class Derived>
template<typename T, typename U>
bool swift::misc::CRangeBase< Derived >::equalPointers ( const T * a,
const U * b )
inlinestaticprotected

Efficiently compare addresses of two objects. Return false if types are not compatible.

Definition at line 169 of file range.h.

◆ equalsBy()

template<class Derived>
template<class T, class Predicate>
bool swift::misc::CRangeBase< Derived >::equalsBy ( const T & other,
Predicate c ) const
inline

Return true if this container equals another container according to the given element equality predicate.

Definition at line 127 of file range.h.

◆ equalsByKeys()

template<class Derived>
template<class T, class Key0, class... Keys>
bool swift::misc::CRangeBase< Derived >::equalsByKeys ( const T & other,
Key0 k0,
Keys... keys ) const
inline

Return true if this container equals another container, considering only the given element members.

Definition at line 138 of file range.h.

◆ findBy() [1/2]

template<class Derived>
template<class K0, class V0, class... KeysValues>
auto swift::misc::CRangeBase< Derived >::findBy ( K0 k0,
V0 v0,
KeysValues... keysValues ) const
inline

Return a copy containing only those elements matching some particular key/value pair(s).

Parameters
k0A pointer to a member function of T.
v0A value to compare against the value returned by k0.
keysValuesZero or more additional pairs of { pointer to member function of T, value to compare it against }.

Definition at line 429 of file range.h.

◆ findBy() [2/2]

template<class Derived>
template<class Predicate>
auto swift::misc::CRangeBase< Derived >::findBy ( Predicate p) const
inline

Return a copy containing only those elements for which a given predicate returns true.

Definition at line 422 of file range.h.

◆ findFirstBy() [1/2]

template<class Derived>
template<class K, class V>
const auto & swift::misc::CRangeBase< Derived >::findFirstBy ( K key,
V value ) const
inline

Return a reference to the first element matching some particular key/value pair(s). Undefined if there is none.

Definition at line 62 of file range.h.

◆ findFirstBy() [2/2]

template<class Derived>
template<class Predicate>
const auto & swift::misc::CRangeBase< Derived >::findFirstBy ( Predicate p) const
inline

Return a reference to the first element for which a given predicate returns true. Undefined if there is none.

Definition at line 54 of file range.h.

◆ findFirstByOrDefault() [1/4]

template<class Derived>
template<class K, class V, class Value>
auto swift::misc::CRangeBase< Derived >::findFirstByOrDefault ( K key,
V value,
const Value & def ) const
inline

Return a copy of the first element matching some particular key/value pair(s), or a default value if there is none.

Definition at line 86 of file range.h.

◆ findFirstByOrDefault() [2/4]

template<class Derived>
template<class T, class K, class V>
auto swift::misc::CRangeBase< Derived >::findFirstByOrDefault ( K T::* key,
V value ) const
inline

Return a copy of the first element matching some particular key/value pair(s), or a default value if there is none.

Definition at line 94 of file range.h.

◆ findFirstByOrDefault() [3/4]

template<class Derived>
template<class Predicate>
auto swift::misc::CRangeBase< Derived >::findFirstByOrDefault ( Predicate p) const
inline

Return a copy of the first element for which a given predicate returns true, or a default value if there is none.

Definition at line 78 of file range.h.

◆ findFirstByOrDefault() [4/4]

template<class Derived>
template<class Predicate, class Value>
auto swift::misc::CRangeBase< Derived >::findFirstByOrDefault ( Predicate p,
const Value & def ) const
inline

Return a copy of the first element for which a given predicate returns true, or a default value if there is none.

Definition at line 70 of file range.h.

◆ randomElement()

template<class Derived>
template<class T>
T swift::misc::CRangeBase< Derived >::randomElement ( ) const
inline

Pick one random element.

Definition at line 145 of file range.h.

◆ randomElements()

template<class Derived>
Derived swift::misc::CRangeBase< Derived >::randomElements ( int n) const
inline

Copy n elements from the container at random.

Definition at line 151 of file range.h.

◆ sampleElements()

template<class Derived>
Derived swift::misc::CRangeBase< Derived >::sampleElements ( int n) const
inline

Copy n elements from the container, randomly selected but evenly distributed.

Definition at line 159 of file range.h.

◆ transform()

template<class Derived>
template<class F>
auto swift::misc::CRangeBase< Derived >::transform ( F function) const
inline

Return a new container generated by applying some transformation function to all elements of this one.

Definition at line 415 of file range.h.


The documentation for this class was generated from the following file: