group Container utils

Container utils

Functions

Name
template <typename CONTAINER >
unsigned int
count(const CONTAINER & c)
Return number of true elements in the container c .
template <typename CONTAINER ,typename FN >
unsigned int
count(const CONTAINER & c, const FN & f)
Return number of elements in the container c for which f(x) is true.
template <typename CONTAINER >
bool
any(const CONTAINER & c)
Return true if x is true for any x in container c, otherwise false.
template <typename CONTAINER ,typename FN >
bool
any(const CONTAINER & c, const FN & f)
Return true if f(x) is true for any x in container c, otherwise false.
template <typename CONTAINER >
bool
all(const CONTAINER & c)
Return true if x is true for all x in container c, otherwise false.
template <typename CONTAINER ,typename FN >
bool
all(const CONTAINER & c, const FN & f)
Return true if f(x) is true for all x in container c, otherwise false.
template <typename CONTAINER >
bool
none(const CONTAINER & c)
Return true if x is false for all x in container c, otherwise false.
template <typename CONTAINER ,typename FN >
bool
none(const CONTAINER & c, const FN & f)
Return true if f(x) is false for all x in container c, otherwise false.
template <typename CONTAINER1 ,typename CONTAINER2 ,typename FN >
const CONTAINER2 &
transform(const CONTAINER1 & in, CONTAINER2 & out, const FN & f)
A single-container-arg version of std::transform, aka map.
template <typename CONTAINER1 ,typename T2 >
std::vector< T2 >
transform(const CONTAINER1 & in, const std::function< T2(typename CONTAINER1::value_type)> & f)
template <typename CONTAINER1 ,typename T ,typename FN >
T
accumulate(const CONTAINER1 & in, const T & init, const FN & f)
A single-container-arg version of std::accumulate, aka reduce.
template <typename CONTAINER >
CONTAINER::value_type
sum(const CONTAINER & c)
Generic sum function, adding x for all x in container c.
template <typename CONTAINER ,typename T >
T
sum(const CONTAINER & c, const T & start)
template <typename CONTAINER ,typename FN ,typename T >
T
sum(const CONTAINER & c, const FN & f, const T & start =T())
Generic sum function, adding fn(x) for all x in container c, starting with start.
template <typename CONTAINER ,typename T >
T &
isum(const CONTAINER & c, T & out)
template <typename CONTAINER ,typename FN ,typename T >
T &
isum(const CONTAINER & c, const FN & f, T & out)
template <typename CONTAINER ,typename FN >
CONTAINER &
ifilter_discard(CONTAINER & c, const FN & f)
template <typename CONTAINER ,typename FN >
CONTAINER &
idiscard(CONTAINER & c, const FN & f)
Alias.
template <typename CONTAINER ,typename FN >
CONTAINER
filter_discard(const CONTAINER & c, const FN & f)
template <typename CONTAINER ,typename FN >
CONTAINER &
discard(CONTAINER & c, const FN & f)
Alias.
template <typename CONTAINER ,typename FN >
CONTAINER &
filter_discard(const CONTAINER & c, const FN & f, CONTAINER & out)
template <typename CONTAINER ,typename FN >
CONTAINER &
discard(CONTAINER & c, const FN & f, CONTAINER & out)
Alias.
template <typename CONTAINER ,typename FN >
CONTAINER &
ifilter_select(CONTAINER & c, const FN & f)
template <typename CONTAINER ,typename FN >
CONTAINER &
iselect(CONTAINER & c, const FN & f)
Alias.
template <typename CONTAINER ,typename FN >
CONTAINER
filter_select(const CONTAINER & c, const FN & f)
template <typename CONTAINER ,typename FN >
CONTAINER
select(const CONTAINER & c, const FN & f)
Alias.
template <typename CONTAINER ,typename FN >
CONTAINER &
filter_select(const CONTAINER & c, const FN & f, CONTAINER & out)
template <typename CONTAINER ,typename FN >
CONTAINER &
select(CONTAINER & c, const FN & f, CONTAINER & out)
Alias.
template <typename CONTAINER >
CONTAINER
slice(const CONTAINER & c, int i, int j)
Slice of the container elements cf. Python’s [i:j] syntax.
template <typename CONTAINER >
CONTAINER
slice(const CONTAINER & c, int i)
Tail slice of the container elements cf. Python’s [i:] syntax.
template <typename CONTAINER >
CONTAINER
head(const CONTAINER & c, int n)
Head slice of the n first container elements.
template <typename CONTAINER >
CONTAINER
tail(const CONTAINER & c, int n)
Tail slice of the n last container elements.
doublemin(const vector< double > & in, double errval =DBL_NAN)
Find the minimum value in the vector.
doublemax(const vector< double > & in, double errval =DBL_NAN)
Find the maximum value in the vector.
pair< double, double >minmax(const vector< double > & in, double errval =DBL_NAN)
Find the minimum and maximum values in the vector.
intmin(const vector< int > & in, int errval =-1)
Find the minimum value in the vector.
intmax(const vector< int > & in, int errval =-1)
Find the maximum value in the vector.
pair< int, int >minmax(const vector< int > & in, int errval =-1)
Find the minimum and maximum values in the vector.

Functions Documentation

function count

template <typename CONTAINER >
inline unsigned int count(
    const CONTAINER & c
)

Return number of true elements in the container c .

function count

template <typename CONTAINER ,
typename FN >
inline unsigned int count(
    const CONTAINER & c,
    const FN & f
)

Return number of elements in the container c for which f(x) is true.

function any

template <typename CONTAINER >
inline bool any(
    const CONTAINER & c
)

Return true if x is true for any x in container c, otherwise false.

function any

template <typename CONTAINER ,
typename FN >
inline bool any(
    const CONTAINER & c,
    const FN & f
)

Return true if f(x) is true for any x in container c, otherwise false.

function all

template <typename CONTAINER >
inline bool all(
    const CONTAINER & c
)

Return true if x is true for all x in container c, otherwise false.

function all

template <typename CONTAINER ,
typename FN >
inline bool all(
    const CONTAINER & c,
    const FN & f
)

Return true if f(x) is true for all x in container c, otherwise false.

function none

template <typename CONTAINER >
inline bool none(
    const CONTAINER & c
)

Return true if x is false for all x in container c, otherwise false.

function none

template <typename CONTAINER ,
typename FN >
inline bool none(
    const CONTAINER & c,
    const FN & f
)

Return true if f(x) is false for all x in container c, otherwise false.

function transform

template <typename CONTAINER1 ,
typename CONTAINER2 ,
typename FN >
inline const CONTAINER2 & transform(
    const CONTAINER1 & in,
    CONTAINER2 & out,
    const FN & f
)

A single-container-arg version of std::transform, aka map.

function transform

template <typename CONTAINER1 ,
typename T2 >
inline std::vector< T2 > transform(
    const CONTAINER1 & in,
    const std::function< T2(typename CONTAINER1::value_type)> & f
)

Todo: Make the function template polymorphic… or specific to ParticleBase

A single-container-arg, return-value version of std::transform, aka map

function accumulate

template <typename CONTAINER1 ,
typename T ,
typename FN >
inline T accumulate(
    const CONTAINER1 & in,
    const T & init,
    const FN & f
)

A single-container-arg version of std::accumulate, aka reduce.

function sum

template <typename CONTAINER >
inline CONTAINER::value_type sum(
    const CONTAINER & c
)

Generic sum function, adding x for all x in container c.

Note: Default-constructs the return type – not always possible! Supply an explicit start value if necessary.

function sum

template <typename CONTAINER ,
typename T >
inline T sum(
    const CONTAINER & c,
    const T & start
)

Note: It’s more more flexible here to not use CONTAINER::value_type, allowing implicit casting to T.

Generic sum function, adding x for all x in container c, starting with start

function sum

template <typename CONTAINER ,
typename FN ,
typename T >
inline T sum(
    const CONTAINER & c,
    const FN & f,
    const T & start =T()
)

Generic sum function, adding fn(x) for all x in container c, starting with start.

function isum

template <typename CONTAINER ,
typename T >
inline T & isum(
    const CONTAINER & c,
    T & out
)

Note: It’s more more flexible here to not use CONTAINER::value_type, allowing implicit casting to T.

In-place generic sum function, adding x on to container out for all x in container c

function isum

template <typename CONTAINER ,
typename FN ,
typename T >
inline T & isum(
    const CONTAINER & c,
    const FN & f,
    T & out
)

Note: It’s more more flexible here to not use CONTAINER::value_type, allowing implicit casting to T.

In-place generic sum function, adding fn(x) on to container out for all x in container c

function ifilter_discard

template <typename CONTAINER ,
typename FN >
inline CONTAINER & ifilter_discard(
    CONTAINER & c,
    const FN & f
)

Todo: Use const std::function<bool(typename CONTAINER::value_type)>… but need polymorphism for ParticleBase

Filter a collection in-place, removing the subset that passes the supplied function

function idiscard

template <typename CONTAINER ,
typename FN >
inline CONTAINER & idiscard(
    CONTAINER & c,
    const FN & f
)

Alias.

function filter_discard

template <typename CONTAINER ,
typename FN >
inline CONTAINER filter_discard(
    const CONTAINER & c,
    const FN & f
)

Todo: Use const std::function<bool(typename CONTAINER::value_type)>… but need polymorphism for ParticleBase

Filter a collection by copy, removing the subset that passes the supplied function

< TodoMore efficient would be copy_if with back_inserter…

function discard

template <typename CONTAINER ,
typename FN >
inline CONTAINER & discard(
    CONTAINER & c,
    const FN & f
)

Alias.

function filter_discard

template <typename CONTAINER ,
typename FN >
inline CONTAINER & filter_discard(
    const CONTAINER & c,
    const FN & f,
    CONTAINER & out
)

Note: New container will be replaced, not appended to

Todo: Use const std::function<bool(typename CONTAINER::value_type)>… but need polymorphism for ParticleBase

Filter a collection by copy into a supplied container, removing the subset that passes the supplied function

function discard

template <typename CONTAINER ,
typename FN >
inline CONTAINER & discard(
    CONTAINER & c,
    const FN & f,
    CONTAINER & out
)

Alias.

function ifilter_select

template <typename CONTAINER ,
typename FN >
inline CONTAINER & ifilter_select(
    CONTAINER & c,
    const FN & f
)

Todo: Use const std::function<bool(typename CONTAINER::value_type)>… but need polymorphism for ParticleBase

Filter a collection in-place, keeping the subset that passes the supplied function

function iselect

template <typename CONTAINER ,
typename FN >
inline CONTAINER & iselect(
    CONTAINER & c,
    const FN & f
)

Alias.

function filter_select

template <typename CONTAINER ,
typename FN >
inline CONTAINER filter_select(
    const CONTAINER & c,
    const FN & f
)

Todo: Use const std::function<bool(typename CONTAINER::value_type)>… but need polymorphism for ParticleBase

Filter a collection by copy, keeping the subset that passes the supplied function

< TodoMore efficient would be copy_if with back_inserter … but is that equally container agnostic?

function select

template <typename CONTAINER ,
typename FN >
inline CONTAINER select(
    const CONTAINER & c,
    const FN & f
)

Alias.

function filter_select

template <typename CONTAINER ,
typename FN >
inline CONTAINER & filter_select(
    const CONTAINER & c,
    const FN & f,
    CONTAINER & out
)

Note: New container will be replaced, not appended to

Todo: Use const std::function<bool(typename CONTAINER::value_type)>… but need polymorphism for ParticleBase

Filter a collection by copy into a supplied container, keeping the subset that passes the supplied function

function select

template <typename CONTAINER ,
typename FN >
inline CONTAINER & select(
    CONTAINER & c,
    const FN & f,
    CONTAINER & out
)

Alias.

function slice

template <typename CONTAINER >
inline CONTAINER slice(
    const CONTAINER & c,
    int i,
    int j
)

Slice of the container elements cf. Python’s [i:j] syntax.

The element at the j index is not included in the returned container. i and j can be negative, treated as backward offsets from the end of the container.

function slice

template <typename CONTAINER >
inline CONTAINER slice(
    const CONTAINER & c,
    int i
)

Tail slice of the container elements cf. Python’s [i:] syntax.

Single-index specialisation of slice(c, i, j)

function head

template <typename CONTAINER >
inline CONTAINER head(
    const CONTAINER & c,
    int n
)

Head slice of the n first container elements.

Negative n means to take the head excluding the n -element tail

function tail

template <typename CONTAINER >
inline CONTAINER tail(
    const CONTAINER & c,
    int n
)

Tail slice of the n last container elements.

Negative n means to take the tail from after the n th element

function min

inline double min(
    const vector< double > & in,
    double errval =DBL_NAN
)

Find the minimum value in the vector.

function max

inline double max(
    const vector< double > & in,
    double errval =DBL_NAN
)

Find the maximum value in the vector.

function minmax

inline pair< double, double > minmax(
    const vector< double > & in,
    double errval =DBL_NAN
)

Find the minimum and maximum values in the vector.

function min

inline int min(
    const vector< int > & in,
    int errval =-1
)

Find the minimum value in the vector.

function max

inline int max(
    const vector< int > & in,
    int errval =-1
)

Find the maximum value in the vector.

function minmax

inline pair< int, int > minmax(
    const vector< int > & in,
    int errval =-1
)

Find the minimum and maximum values in the vector.


Updated on 2022-08-07 at 20:17:17 +0100