Rivet: Container utils

| Rivet 3.1.9

Functions
Container utils

## Functions
template<typename CONTAINER >
unsigned int | Rivet::count (const CONTAINER &c)
| Return number of true elements in the container c .
template<typename CONTAINER , typename FN >
unsigned int | Rivet::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 | Rivet::any (const CONTAINER &c)
| Return true if x is true for any x in container c, otherwise false.
template<typename CONTAINER , typename FN >
bool | Rivet::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 | Rivet::all (const CONTAINER &c)
| Return true if x is true for all `x` in container c, otherwise false.
template<typename CONTAINER , typename FN >
bool | Rivet::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 | Rivet::none (const CONTAINER &c)
| Return true if x is false for all `x` in container c, otherwise false.
template<typename CONTAINER , typename FN >
bool | Rivet::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 & | Rivet::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 > | Rivet::transform (const CONTAINER1 &in, const std::function< T2(typename CONTAINER1::value_type)> &f)
template<typename CONTAINER1 , typename T , typename FN >
T | Rivet::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 | Rivet::sum (const CONTAINER &c)
| Generic sum function, adding `x` for all `x` in container c.
template<typename CONTAINER , typename T >
T | Rivet::sum (const CONTAINER &c, const T &start)
template<typename CONTAINER , typename FN , typename T >
T | Rivet::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 & | Rivet::isum (const CONTAINER &c, T &out)
template<typename CONTAINER , typename FN , typename T >
T & | Rivet::isum (const CONTAINER &c, const FN &f, T &out)
template<typename CONTAINER , typename FN >
CONTAINER & | Rivet::ifilter_discard (CONTAINER &c, const FN &f)
template<typename CONTAINER , typename FN >
CONTAINER & | Rivet::idiscard (CONTAINER &c, const FN &f)
| Alias.
template<typename CONTAINER >
CONTAINER & | Rivet::ifilter_discard (CONTAINER &c, const typename CONTAINER::value_type &y)
template<typename CONTAINER >
CONTAINER & | Rivet::idiscard (CONTAINER &c, const typename CONTAINER::value_type &y)
| Version with element-equality comparison in place of a function.
template<typename CONTAINER >
CONTAINER & | Rivet::ifilter_discard_if_any (CONTAINER &c, const CONTAINER &ys)
template<typename CONTAINER >
CONTAINER & | Rivet::idiscard_if_any (CONTAINER &c, const CONTAINER &ys)
| Version with element-equality comparisons in place of a function.
template<typename CONTAINER , typename FN >
CONTAINER | Rivet::filter_discard (const CONTAINER &c, const FN &f)
template<typename CONTAINER , typename FN >
CONTAINER | Rivet::discard (const CONTAINER &c, const FN &f)
| Alias.
template<typename CONTAINER >
CONTAINER | Rivet::filter_discard (const CONTAINER &c, const typename CONTAINER::value_type &y)
template<typename CONTAINER >
CONTAINER | Rivet::discard (const CONTAINER &c, const typename CONTAINER::value_type &y)
| Version with element-equality comparison in place of a function.
template<typename CONTAINER >
CONTAINER | Rivet::filter_discard_if_any (const CONTAINER &c, const CONTAINER &ys)
template<typename CONTAINER >
CONTAINER | Rivet::discard_if_any (const CONTAINER &c, const CONTAINER &ys)
| Version with element-equality comparisons in place of a function.
template<typename CONTAINER , typename FN >
CONTAINER & | Rivet::filter_discard (const CONTAINER &c, const FN &f, CONTAINER &out)
template<typename CONTAINER , typename FN >
CONTAINER & | Rivet::discard (const CONTAINER &c, const FN &f, CONTAINER &out)
| Alias.
template<typename CONTAINER >
CONTAINER & | Rivet::filter_discard (const CONTAINER &c, const typename CONTAINER::value_type &y, CONTAINER &out)
template<typename CONTAINER >
CONTAINER & | Rivet::discard (const CONTAINER &c, const typename CONTAINER::value_type &y, CONTAINER &out)
| Version with element-equality comparison in place of a function.
template<typename CONTAINER >
CONTAINER & | Rivet::filter_discard_if_any (const CONTAINER &c, const CONTAINER &ys, CONTAINER &out)
template<typename CONTAINER >
CONTAINER & | Rivet::discard_if_any (const CONTAINER &c, const CONTAINER &ys, CONTAINER &out)
| Version with element-equality comparisons in place of a function.
template<typename CONTAINER , typename FN >
CONTAINER & | Rivet::ifilter_select (CONTAINER &c, const FN &f)
template<typename CONTAINER , typename FN >
CONTAINER & | Rivet::iselect (CONTAINER &c, const FN &f)
| Alias.
template<typename CONTAINER >
CONTAINER & | Rivet::ifilter_select_if_any (CONTAINER &c, const CONTAINER &ys)
template<typename CONTAINER >
CONTAINER & | Rivet::iselect_if_any (CONTAINER &c, const CONTAINER &ys)
| Version with element-equality comparisons in place of a function.
template<typename CONTAINER , typename FN >
CONTAINER | Rivet::filter_select (const CONTAINER &c, const FN &f)
template<typename CONTAINER , typename FN >
CONTAINER | Rivet::select (const CONTAINER &c, const FN &f)
| Alias.
template<typename CONTAINER >
CONTAINER | Rivet::filter_select_if_any (const CONTAINER &c, const CONTAINER &ys)
template<typename CONTAINER >
CONTAINER | Rivet::select_if_any (const CONTAINER &c, const CONTAINER &ys)
| Version with element-equality comparisons in place of a function.
template<typename CONTAINER , typename FN >
CONTAINER & | Rivet::filter_select (const CONTAINER &c, const FN &f, CONTAINER &out)
template<typename CONTAINER , typename FN >
CONTAINER & | Rivet::select (const CONTAINER &c, const FN &f, CONTAINER &out)
| Alias.
template<typename CONTAINER >
CONTAINER & | Rivet::filter_select_if_any (const CONTAINER &c, const CONTAINER &ys, CONTAINER &out)
template<typename CONTAINER >
CONTAINER & | Rivet::select_if_any (const CONTAINER &c, const CONTAINER &ys, CONTAINER &out)
| Version with element-equality comparisons in place of a function.
template<typename CONTAINER >
CONTAINER | Rivet::slice (const CONTAINER &c, int i, int j)
| Slice of the container elements cf. Python's [i:j] syntax.
template<typename CONTAINER >
CONTAINER | Rivet::slice (const CONTAINER &c, int i)
| Tail slice of the container elements cf. Python's [i:] syntax.
template<typename CONTAINER >
CONTAINER | Rivet::head (const CONTAINER &c, int n)
| Head slice of the n first container elements.
template<typename CONTAINER >
CONTAINER | Rivet::tail (const CONTAINER &c, int n)
| Tail slice of the n last container elements.
double | Rivet::min (const vector< double > &in, double errval=DBL_NAN)
| Find the minimum value in the vector.
double | Rivet::max (const vector< double > &in, double errval=DBL_NAN)
| Find the maximum value in the vector.
pair< double, double > | Rivet::minmax (const vector< double > &in, double errval=DBL_NAN)
| Find the minimum and maximum values in the vector.
int | Rivet::min (const vector< int > &in, int errval=-1)
| Find the minimum value in the vector.
int | Rivet::max (const vector< int > &in, int errval=-1)
| Find the maximum value in the vector.
pair< int, int > | Rivet::minmax (const vector< int > &in, int errval=-1)
| Find the minimum and maximum values in the vector.

## Detailed Description

## Function Documentation

## ◆ filter_discard() [1/4]

template<typename CONTAINER , typename FN >

CONTAINER Rivet::filter_discard | ( | const CONTAINER & | c,
|  | const FN & | f
| ) |  |
| inline

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

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

Deprecated:
  Use discard()

<

Todo:
  More efficient would be copy_if with back_inserter...

References Rivet::ifilter_discard().

## ◆ filter_discard() [2/4]

template<typename CONTAINER , typename FN >

CONTAINER & Rivet::filter_discard | ( | const CONTAINER & | c,
|  | const FN & | f,
|  | CONTAINER & | out
| ) |  |
| inline

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

Note
  New container will be replaced, not appended to

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

Deprecated:
  Use discard()

References Rivet::filter_discard().

## ◆ filter_discard() [3/4]

template<typename CONTAINER >

CONTAINER Rivet::filter_discard | ( | const CONTAINER & | c,
|  | const typename CONTAINER::value_type & | y
| ) |  |
| inline

Version with element-equality comparison in place of a function

Deprecated:
  Use discard()

References Rivet::filter_discard().

## ◆ filter_discard() [4/4]

template<typename CONTAINER >

CONTAINER & Rivet::filter_discard | ( | const CONTAINER & | c,
|  | const typename CONTAINER::value_type & | y,
|  | CONTAINER & | out
| ) |  |
| inline

Version with element-equality comparison in place of a function

Deprecated:
  Use discard()

References Rivet::filter_discard().

## ◆ filter_discard_if_any() [1/2]

template<typename CONTAINER >

CONTAINER Rivet::filter_discard_if_any | ( | const CONTAINER & | c,
|  | const CONTAINER & | ys
| ) |  |
| inline

Version with several element-equality comparisons in place of a function

Deprecated:
  Use idiscard_if_any()

References Rivet::contains(), and Rivet::filter_discard().

## ◆ filter_discard_if_any() [2/2]

template<typename CONTAINER >

CONTAINER & Rivet::filter_discard_if_any | ( | const CONTAINER & | c,
|  | const CONTAINER & | ys,
|  | CONTAINER & | out
| ) |  |
| inline

Version with several element-equality comparisons in place of a function

Deprecated:
  Use idiscard_if_any()

References Rivet::contains(), and Rivet::filter_discard().

## ◆ filter_select() [1/2]

template<typename CONTAINER , typename FN >

CONTAINER Rivet::filter_select | ( | const CONTAINER & | c,
|  | const FN & | f
| ) |  |
| inline

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

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

Deprecated:
  Use select()

<

Todo:
  More efficient would be copy_if with back_inserter ... but is that equally container agnostic?

References Rivet::ifilter_select().

## ◆ filter_select() [2/2]

template<typename CONTAINER , typename FN >

CONTAINER & Rivet::filter_select | ( | const CONTAINER & | c,
|  | const FN & | f,
|  | CONTAINER & | out
| ) |  |
| inline

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

Note
  New container will be replaced, not appended to

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

Deprecated:
  Use select()

References Rivet::filter_select().

## ◆ filter_select_if_any() [1/2]

template<typename CONTAINER >

CONTAINER Rivet::filter_select_if_any | ( | const CONTAINER & | c,
|  | const CONTAINER & | ys
| ) |  |
| inline

Version with several element-equality comparisons in place of a function

Deprecated:
  Use select_if_any()

References Rivet::contains(), and Rivet::filter_select().

## ◆ filter_select_if_any() [2/2]

template<typename CONTAINER >

CONTAINER & Rivet::filter_select_if_any | ( | const CONTAINER & | c,
|  | const CONTAINER & | ys,
|  | CONTAINER & | out
| ) |  |
| inline

Version with several element-equality comparisons in place of a function

Deprecated:
  Use iselect_if_any()

References Rivet::contains(), and Rivet::filter_select().

## ◆ head()

template<typename CONTAINER >

CONTAINER Rivet::head | ( | const CONTAINER & | c,
|  | int | n
| ) |  |
| inline

Head slice of the n first container elements.

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

References Rivet::slice().

## ◆ ifilter_discard() [1/2]

template<typename CONTAINER , typename FN >

CONTAINER & Rivet::ifilter_discard | ( | CONTAINER & | c,
|  | const FN & | f
| ) |  |
| inline

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

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

Deprecated:
  Use idiscard()

## ◆ ifilter_discard() [2/2]

template<typename CONTAINER >

CONTAINER & Rivet::ifilter_discard | ( | CONTAINER & | c,
|  | const typename CONTAINER::value_type & | y
| ) |  |
| inline

Version with element-equality comparison in place of a function

Deprecated:
  Use idiscard()

References Rivet::ifilter_discard().

## ◆ ifilter_discard_if_any()

template<typename CONTAINER >

CONTAINER & Rivet::ifilter_discard_if_any | ( | CONTAINER & | c,
|  | const CONTAINER & | ys
| ) |  |
| inline

Version with several element-equality comparisons in place of a function

Deprecated:
  Use idiscard()

References Rivet::contains(), and Rivet::ifilter_discard().

## ◆ ifilter_select()

template<typename CONTAINER , typename FN >

CONTAINER & Rivet::ifilter_select | ( | CONTAINER & | c,
|  | const FN & | f
| ) |  |
| inline

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

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

Deprecated:
  Use iselect()

References Rivet::ifilter_discard().

## ◆ ifilter_select_if_any()

template<typename CONTAINER >

CONTAINER & Rivet::ifilter_select_if_any | ( | CONTAINER & | c,
|  | const CONTAINER & | ys
| ) |  |
| inline

Version with several element-equality comparisons in place of a function

Deprecated:
  Use iselect_if_any()

References Rivet::contains(), and Rivet::ifilter_select().

## ◆ isum() [1/2]

template<typename CONTAINER , typename FN , typename T >

T & Rivet::isum | ( | const CONTAINER & | c,
|  | const FN & | f,
|  | T & | out
| ) |  |
| inline

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

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

## ◆ isum() [2/2]

template<typename CONTAINER , typename T >

T & Rivet::isum | ( | const CONTAINER & | c,
|  | T & | out
| ) |  |
| inline

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

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

## ◆ slice() [1/2]

template<typename CONTAINER >

CONTAINER Rivet::slice | ( | const CONTAINER & | c,
|  | int | i
| ) |  |
| inline

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

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

References Rivet::slice().

## ◆ slice() [2/2]

template<typename CONTAINER >

CONTAINER Rivet::slice | ( | const CONTAINER & | c,
|  | int | i,
|  | int | j
| ) |  |
| inline

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.

Referenced by Rivet::head(), Rivet::DressedLepton::photons(), Rivet::slice(), and Rivet::tail().

## ◆ sum() [1/2]

template<typename CONTAINER >

CONTAINER::value_type Rivet::sum | ( | const CONTAINER & | c | ) |
| inline

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.

Referenced by Rivet::PercentileProjection::PercentileProjection().

## ◆ sum() [2/2]

template<typename CONTAINER , typename T >

T Rivet::sum | ( | const CONTAINER & | c,
|  | const T & | start
| ) |  |
| inline

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

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

## ◆ tail()

template<typename CONTAINER >

CONTAINER Rivet::tail | ( | const CONTAINER & | c,
|  | int | n
| ) |  |
| inline

Tail slice of the n last container elements.

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

References Rivet::slice().

## ◆ transform()

template<typename CONTAINER1 , typename T2 >

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

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

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