Utility

Functions

std::vector<int> range(const int n)

Returns the vector [0, 1, 2, …, n-1].

template<class T>
std::vector<T> range(const T begin, const T end, const T incr = Constants<T>::one())

Returns a vector [begin, begin + incr, begin + 2*incr, … ]. The array ends at end (excluded).

template<class T>
T sum(const std::vector<T> &vect)

Returns the sum of the elements of a vector.

template<class T, class U, typename F>
std::vector<U> apply_fct(const std::vector<T> &vect, F f)

Applies a function on all the elements of a vector, and returns the obtained vector.

A lambda can be passed: apply_fct<int, long long>(range(7), [](int x) { return (long long)x * x; })