Querying properties of objects:
Producing objects:
Binary operations:
Unary operations:
Operation on operations:
Queries about operations:
Compile-time queries about nested call expressions:
Indicates left direction for operations that take an operation. This class is used only at compile-time and remains incomplete.
Indicates right direction for operations that take an operation. This class is used only at compile-time and remains incomplete.
Indicates either left or right direction for operations that take an operation. This can only be used if the direction is irrelevant. For example, for real numbers, there is no difference between left and right division. This class is used only at compile-time and remains incomplete.
Metafunction that assigns magma tags to types. All types that have the same magma tag are in the same magma.
The type for which the magma tag is required.
Metafunction that indicates whether a type is in a magma.
The type for which the status is required.
Rime merge policy for magmas.
If you would like to return one value or another based on a run-time or compile-time condition, then say
rime::if_ <merge_magma> (condition, magma1, magma2)
This will automatically return the correctly general type.
This wraps operation::unify_type to form a metafunction implementing a Rime merge policy. If Left and Right are the same type, then it is returned unchanged. Otherwise, some conversion is necessary, so operation::unify_type is called with the decayed types to find the common type.
Convert a magma type to a type in the same magma that can contain the result of any combination of a number of binary operations applied to it.
For example, a single_sequence under plus will generalise to optional_sequence; under times (or under both) it will generalise to a sequence.
A meta::vector of binary operations, usually from namespace callable.
The magma type to be generalised.
Some magmas have values that are not in the magma, like not-a-number values in standard floating-point types.
To support composite magmas (such as math::lexicographical), different comparison operations are available. math::compare(), if implemented, gives a strict weak ordering, and is often equaivalent to operator<. order <...> also implements a comparison, which may be related to compare, but this is not necessary. order <choose>, if defined, returns true if the left value is better, in some sense, than the right value. If it is defined, then math::choose() will return the better of two values.
Some magmas, cost, for example, implement the same behaviour with the operation plus. order <plus> then compares two values; plus itself returns the best (in this case, lowest-cost) of two.
Return whether magma1 comes before magma2 in a strict weak ordering. This returns false for both orders of arguments iff equal returns true.
Return whether operation Operation will return magma1, or magma2. This operation is only available if Operation applies a strict weak ordering and returns either magma1 or magma2.
The operation that returns either either magma1 or magma2.
A type that is in a magma that the return type should be in. Note that the return type is not necesssarily that type.
A type that is in a magma that the return type should be in. Note that the return type is not necessarily that type.
The callable type that represents the operation.
(optional if Operation is given as a template argument) A callable that represents the operation.
A type that is in a magma that the return type should be in. Note that the return type is not necessarily that type.
The callable type that represents the operation.
(optional if Operation is given as a template argument) A callable that represents the operation.
A type that is in a magma that the return type should be in. Note that the return type is not necessarily that type.
A type that is in a magma that the return type should be in. Note that the return type is not necessarily that type.
A boolean, which can be a compile-time or a run-time value.
The direction of the division.
Also known as numerator.
Also known as denominator.
The direction of the subtraction.
The object that the subtrahend will be subtracted from.
The object that will be subtracted from the minuend.
(optional: the default is math::either) The direction of the inverse. A left inverse (indicated with math::left) means that, say, math::inverse <left, callable::plus> (a) + a is equal to the additive identity.
The operation that the inverse is with respect to.
(optional if Operation is given as a template argument) The operation that the inverse is with respect to.
The value to be inverted.
Compute the reverse of a value. It is required that operation (reverse (a), reverse (b)) == reverse (operation (a, b)). The return type may be in a different magma. For example, this may reverse the elements of a left sequence semiring and return them as a right sequence semiring. However, it is required that reverse (reverse (a)) == a and that the result type of applying reverse twice returns a type in the same magma.
For commutative operations, the implementation may just return the magma passed in without any changes.
The operation can be given as a type argument, or as a value argument.
The operation that the inverse is with respect to.
(optional if Operation is given as a template argument) The operation that the inverse is with respect to.
The value to be inverted.
Output a human-readable representation of the magma to a stream.
The output stream to write to.
The value to output the representation of.
The following are operations on operations.
Return the inverse of the operation. For example, inverse_operation (times) will return an object of type callable::divide<>. The operation can be given as a type argument, or as a value argument.
(optional: the default is math::either.) The direction of the inverse. For example, in a sequence semiring, in which math::times concatenates two sequences, left division and right division are different.
The callable type that represents the operation.
(optional if Operation is given as a template argument) A callable that represents the operation.
Whether an operation on a magma is associative. That is, whether in an expression that applies the same operation a number of times, like 1+2+3, changing the position of the brackets does not change the result.
It is possible that the operation is approximate but it is still approximately associative. In that case, this will evaluate to true.
It is possible to instantiate this with the standard type argument syntax, documented below, or with one argument in a cute syntax, one of: Operation (Magma1, Magma2); Operation (Magma1, Operation (Magma2, Magma3)); Operation (Operation (Magma1, Magma2), Magma3).
The operation, normally a type in namespace math::callable.
A type that belongs to the magma of interest.
Whether an operation on a magma is commutative. That is, whether the operands of the operation can be exchanged without changing the result.
It is possible that the operation is approximate but it is still approximately associative. In that case, this will evaluate to true.
It is possible to instantiate this with the standard type argument syntax, documented below, or with one argument in a cute syntax: Operation (Magma1, Magma2).
The operation, normally a type in namespace math::callable.
A type that belongs to the magma of interest.
Whether an operation on a magma is idempotent. That is, whether the operation applied on the same value, it returns that value again. For example, if the operation returns the maximum of two elements, it is idempotent because max (a, a) == a.
It is possible to instantiate this with the standard type argument syntax, documented below, or with one argument in a cute syntax: Operation (Magma1, Magma2).
The operation, normally a type in namespace math::callable.
A type that belongs to the magma of interest.
Whether an operation on a magma is a path operation. That is, whether the operation returns either the one or the other operand.
This implies idempotent <Magma, Operation>.
It is possible to instantiate this with the standard type argument syntax, documented below, or with one argument in a cute syntax: Operation (Magma1, Magma2).
The operation, normally a type in namespace math::callable.
A type that belongs to the magma of interest.
Whether an operation on a magma distributes over another operation on the same magma. For example, a semiring requires that a * (b + c) == (a * b) + (a * c). This is left distributivity; the mirror image is right distributivity.
It is possible to instantiate this with the standard type argument syntax, documented below, or with one argument in a cute syntax: OuterOperation (Magma1, InnerOperation (Magma2, Magma3)) (for left distributivity) or OuterOperation (InnerOperation (Magma1, Magma2), Magma3) (for right distributivity).
The direction of the distributivity: math::left, math::right, or math::either.
The outer operation: in the example, times.
The inner operation: in the example, plus.
A type that belongs to the magma of interest.
Indicate whether a magma is a monoid. A monoid is a magma with an associative operation and an identity.
The operation, normally a type in namespace math::callable.
A type that belongs to the magma of interest.
Indicate whether a magma is a semiring. This describes a number of properties related to the magma’s behaviour under two operations, normally multiplication and addition.
The direction of interest. math::either makes this check whether Magma is a normal semiring. math::left or math::right can be used to check whether Magma is a left of right semiring.
The “multiply” operation, normally math::callable::times.
The “add” operation, normally math::callable::plus.
A type that belongs to the magma of interest.
These are convenient ways of querying the availability or the results of an expression composed of magma operations. Internally, this uses the nested callable protocol for function objects.
Compile-time constant that returns whether a nested call expression has been implemented for a particular set of parameters.
The nested call expression of which the return type is sought.
Find the result of a nested call expression.
The nested call expression of which the return type is sought.
Find the result of a nested call expression, or the second argument. If no second argument is given, do not yield any type (useful to disable a function overload using SFINAE).
The nested call expression of which the return type is sought.
(optional) The type that should be returned if has <Expression> evaluates to false. If this is not given, then type will not be defined.
Compile-time constant that returns whether an operation is approximate for a particular set of parameters.
The nested call expression. If any single operation in the expression is approximate, the whole expression is assumed to be approximate. (This is the conservative approach.)
The following types of exception can be thrown:
Exception that is thrown by the explicit constructor of a magma if the value passed in cannot be contained by the magma type to be constructed.
Exception that indicates an error while performing an inverse operation.
Exception that indicates that an inverse operation is not defined for the two values that it is called with.
Exception that indicates that the inverse of an annihilator was required. For example, an inverse operation was called with an annihilator as its second argument. Division by zero is an example of this.
Exception that indicates that divide was called with (generalised) zero as its second argument.