Constant Expressions

Contains an assortment of constexpr functions. More...

Functions

template<typename List , Requires< not tt::is_a_v< tmpl::list, tmpl::front< List >>> = nullptr>
constexpr auto make_cpp17_array_from_list () -> cpp17::array< std::decay_t< decltype(tmpl::front< List >::value)>, tmpl::size< List >::value >
Make an array from a typelist that holds std::integral_constant's all of which have the same value_type More...

template<typename T , Requires< tt::is_integer_v< T > and cpp17::is_unsigned_v< T >> = nullptr>
constexpr T two_to_the (T n)
Compute 2 to the n for integral types. More...

constexpr size_t get_nth_bit (const size_t i, const size_t N)
Get the nth bit from the right, counting from zero. More...

template<typename T >
decltype(auto) constexpr square (const T &x)
Compute the square of x

template<typename T >
decltype(auto) constexpr cube (const T &x)
Compute the cube of x

constexpr uint64_t falling_factorial (const uint64_t x, const uint64_t n) noexcept
Compute the falling factorial of $(x)_{n}$. More...

constexpr uint64_t factorial (const uint64_t n) noexcept
Compute the factorial of $n!$.

template<int N, typename T >
decltype(auto) constexpr pow (const T &t) noexcept
Compute t^N where N is an integer (positive or negative) More...

template<typename T , Requires< tt::is_integer_v< T > or cpp17::is_floating_point_v< T >> = nullptr>
constexpr T ce_abs (const T &x) noexcept(noexcept(x< 0 ? -x :x))
Compute the absolute value of of its argument. More...

constexpr double ce_fabs (const double x) noexcept
Compute the absolute value of its argument.

template<class T , class Compare = std::less<>>
constexpr const T & cpp17::clamp (const T &v, const T &lo, const T &hi, Compare comp=Compare())
Clamps the value between lo and hi. More...

template<size_t NumTerms, typename Function , Requires< NumTerms==1 > = nullptr>
decltype(auto) constexpr constexpr_sum (Function &&f) noexcept
Returns f(ic<0>{}) + f(ic<1>{}) + ... + f(ic<NumTerms-1>{}) where ic<N> stands for std::integral_constant<size_t, N>. This function allows the result types of each operation to be different, and so works efficiently with expression templates. More...

template<typename List , Requires< not tt::is_a_v< tmpl::list, tmpl::front< List >>> = nullptr>
constexpr auto make_array_from_list () -> std::array< std::decay_t< decltype(tmpl::front< List >::value)>, tmpl::size< List >::value >
Make an array from a typelist that holds std::integral_constant's all of which have the same value_type More...

constexpr size_t cstring_length (const char *str) noexcept
Compute the length of a const char* at compile time.

constexpr size_t cstring_hash (const char *str) noexcept
Compute a hash of a const char* at compile time.

template<size_t I, typename T , size_t Size>
constexpr std::array< std::decay_t< T >, Size > replace_at (const std::array< T, Size > &arr, T value)
Replace at compile time the Ith entry in the array with value

template<typename T , typename S , size_t size>
constexpr bool array_equal (const std::array< T, size > &lhs, const std::array< S, size > &rhs, const size_t i=0) noexcept
Check at compile time if two std::arrays are equal.

template<typename T >
constexpr const T & cpp17::as_const (const T &t) noexcept
Returns a const reference to its argument.

template<typename T >
constexpr const T & max_by_magnitude (const T &a, const T &b)
Return the argument with the largest magnitude. More...

template<typename T >
constexpr T max_by_magnitude (std::initializer_list< T > ilist)
Return the argument with the largest magnitude. More...

template<typename T >
constexpr const T & min_by_magnitude (const T &a, const T &b)
Return the argument with the smallest magnitude. More...

template<typename T >
constexpr T min_by_magnitude (std::initializer_list< T > ilist)
Return the argument with the smallest magnitude. More...

Detailed Description

Contains an assortment of constexpr functions.

Description

Contains an assortment of constexpr functions that are useful for metaprogramming, or efficient mathematical computations, such as exponentiating to an integer power, where the power is known at compile time.

◆ ce_abs()

template<typename T , Requires< tt::is_integer_v< T > or cpp17::is_floating_point_v< T >> = nullptr>
 constexpr T ce_abs ( const T & x )
noexcept

Compute the absolute value of of its argument.

The argument must be comparable to an int and must be negatable.

◆ clamp()

template<class T , class Compare = std::less<>>
 constexpr const T& cpp17::clamp ( const T & v, const T & lo, const T & hi, Compare comp = Compare() )

Clamps the value between lo and hi.

If v compares less than lo, returns lo; otherwise if hi compares less than v, returns hi; otherwise returns v.

◆ constexpr_sum()

template<size_t NumTerms, typename Function , Requires< NumTerms==1 > = nullptr>
 decltype(auto) constexpr constexpr_sum ( Function && f )
noexcept

Returns f(ic<0>{}) + f(ic<1>{}) + ... + f(ic<NumTerms-1>{}) where ic<N> stands for std::integral_constant<size_t, N>. This function allows the result types of each operation to be different, and so works efficiently with expression templates.

Note
When summing expression templates one must be careful of referring to temporaries in f.

◆ falling_factorial()

 constexpr uint64_t falling_factorial ( const uint64_t x, const uint64_t n )
noexcept

Compute the falling factorial of $(x)_{n}$.

Note
The largest representable factorial is 20!. It is up to the user to ensure this is satisfied

◆ get_nth_bit()

 constexpr size_t get_nth_bit ( const size_t i, const size_t N )

Get the nth bit from the right, counting from zero.

Parameters
 i the value to be acted on. N which place to extract the bit

Returns: the value of the bit at that place.

◆ make_array_from_list()

template<typename List , Requires< not tt::is_a_v< tmpl::list, tmpl::front< List >>> = nullptr>
 constexpr auto make_array_from_list ( ) -> std::array::value)>, tmpl::size::value>
inline

Make an array from a typelist that holds std::integral_constant's all of which have the same value_type

Make an array of arrays from a typelist that holds typelists of std::integral_constant's all of which have the same value_type

Template Parameters
 List the typelist of std::integral_constant's

Returns: array of integral values from the typelist

Template Parameters
 List the typelist of typelists of std::integral_constant's

Returns: array of arrays of integral values from the typelists

◆ make_cpp17_array_from_list()

template<typename List , Requires< not tt::is_a_v< tmpl::list, tmpl::front< List >>> = nullptr>
 constexpr auto make_cpp17_array_from_list ( ) -> cpp17::array::value)>, tmpl::size::value>
inline

Make an array from a typelist that holds std::integral_constant's all of which have the same value_type

Template Parameters
 List the typelist of std::integral_constant's

Returns: array of integral values from the typelist

◆ max_by_magnitude() [1/2]

template<typename T >
 constexpr const T& max_by_magnitude ( const T & a, const T & b )

Return the argument with the largest magnitude.

Magnitude is determined by constexpr_abs. In case of a tie, returns the leftmost of the tied values.

◆ max_by_magnitude() [2/2]

template<typename T >
 constexpr T max_by_magnitude ( std::initializer_list< T > ilist )

Return the argument with the largest magnitude.

Magnitude is determined by constexpr_abs. In case of a tie, returns the leftmost of the tied values.

◆ min_by_magnitude() [1/2]

template<typename T >
 constexpr const T& min_by_magnitude ( const T & a, const T & b )

Return the argument with the smallest magnitude.

Magnitude is determined by constexpr_abs. In case of a tie, returns the leftmost of the tied values.

◆ min_by_magnitude() [2/2]

template<typename T >
 constexpr T min_by_magnitude ( std::initializer_list< T > ilist )

Return the argument with the smallest magnitude.

Magnitude is determined by constexpr_abs. In case of a tie, returns the leftmost of the tied values.

◆ pow()

template<int N, typename T >
 decltype(auto) constexpr pow ( const T & t )
noexcept

Compute t^N where N is an integer (positive or negative)

Warning
If passing an integer this will do integer arithmetic, e.g. pow<-10>(2) == 0 evaluates to true
For optimization, it is assumed that the pow<0> of a vector type (e.g. DataVector) will not be used for initialization or directly indexed, so pow<0> returns simply 1.0. In the case of use for initialization, a constructor should be used instead, and in the case of a direct index, the expression may be simplifyable to avoid the use of pow<0> altogether. If a more complete treatment of pow<0> is required, further overloads may be added to the ConstantExpressions_detail namespace.
Template Parameters
 N the integer power being raised to in $t^N$
Parameters
 t the value being exponentiated

Returns: value $t^N$ determined via repeated multiplication

◆ two_to_the()

template<typename T , Requires< tt::is_integer_v< T > and cpp17::is_unsigned_v< T >> = nullptr>
 constexpr T two_to_the ( T n )

Compute 2 to the n for integral types.

Parameters
 n the power of two to compute.

Returns: 2^n