Sequoia
Loading...
Searching...
No Matches
Variables
Arithmetic Properties

Tools to reflect on whether types expose the standard arithmetic operations. More...

Variables

template<class T >
constexpr bool sequoia::maths::is_addable_v
 Compile time constant for addability.
 
template<class T >
constexpr bool sequoia::maths::is_subtractable_v
 Compile time constant for subtractability.
 
template<class T >
constexpr bool sequoia::maths::is_multiplicable_v
 Compile time constant for multiplicability.
 
template<class T >
constexpr bool sequoia::maths::is_divisible_v
 Compile time constant for divisibility.
 

Detailed Description

Tools to reflect on whether types expose the standard arithmetic operations.

The main subtlety for the topics that will concern us is division. From the perspective of abstract algebra, multiplication is the more primitive operation. If each element of a set has a multiplicative inverse then for each element, a, there exists a single element, a^{-1}, such that

a * a^{-1} = 1

From this, a division operation can be defined according to

a / b = a  * b^{-1}

However, there are common types that we will deal with - such as ints and size_ts - for which most elements do not have multiplicative inverses valued within the type. A simple example is int x = 2. The multiplicative inverse is 1/2, which is not an int.

Nevertheless, C++'s arithmetic types define division. For signed types this corresponds to a so-called Euclidean domain. For the unsigned types the operation is algorithmically the same, but I actually don't know the name for the associated mathematical structure.

Regardless, the purpose of the utilities in the following set is simply naive reflection on whether particular operations exist in the C++ language and not the nuanced semantics. Therefore, it would be incorrect to conclude that, just because a type is addable, subtractable, multiplicable and divisible that it models a field.

Variable Documentation

◆ is_addable_v

template<class T >
constexpr bool sequoia::maths::is_addable_v
inlineconstexpr
Initial value:
{
requires(T& t) {
{ t += t } -> std::same_as<T&>;
{ t + t } -> std::convertible_to<T>;
}
}

Compile time constant for addability.

◆ is_divisible_v

template<class T >
constexpr bool sequoia::maths::is_divisible_v
inlineconstexpr
Initial value:
{
requires(T& t) {
{ t /= t } -> std::same_as<T&>;
{ t / t } -> std::convertible_to<T>;
}
}

Compile time constant for divisibility.

◆ is_multiplicable_v

template<class T >
constexpr bool sequoia::maths::is_multiplicable_v
inlineconstexpr
Initial value:
{
requires(T& t) {
{ t *= t } -> std::same_as<T&>;
{ t * t } -> std::convertible_to<T>;
}
}

Compile time constant for multiplicability.

◆ is_subtractable_v

template<class T >
constexpr bool sequoia::maths::is_subtractable_v
inlineconstexpr
Initial value:
{
requires(T& t) {
{ t -= t } -> std::same_as<T&>;
{ t - t } -> std::convertible_to<T>;
}
}

Compile time constant for subtractability.