 Boost.Hana  1.2.0 Your standard library for metaprogramming ## Description

The Group concept represents Monoids where all objects have an inverse w.r.t. the Monoid's binary operation.

A Group is an algebraic structure built on top of a Monoid which adds the ability to invert the action of the Monoid's binary operation on any element of the set. Specifically, a Group is a Monoid (S, +) such that every element s in S has an inverse (say s') which is such that

s + s' == s' + s == identity of the Monoid

There are many examples of Groups, one of which would be the additive Monoid on integers, where the inverse of any integer n is the integer -n. The method names used here refer to exactly this model.

## Minimal complete definitions

1. minus
When minus is specified, the negate method is defaulted by setting
negate(x) = minus(zero<G>(), x)
2. negate
When negate is specified, the minus method is defaulted by setting
minus(x, y) = plus(x, negate(y))

## Laws

For all objects x of a Group G, the following laws must be satisfied:

plus(x, negate(x)) == zero<G>() // right inverse
plus(negate(x), x) == zero<G>() // left inverse

## Refined concept

Monoid

## Concrete models

hana::integral_constant

## Free model for non-boolean arithmetic data types

A data type T is arithmetic if std::is_arithmetic<T>::value is true. For a non-boolean arithmetic data type T, a model of Group is automatically defined by setting

minus(x, y) = (x - y)
negate(x) = -x
Note
The rationale for not providing a Group model for bool is the same as for not providing a Monoid model.

## Structure-preserving functions

Let A and B be two Groups. A function f : A -> B is said to be a Group morphism if it preserves the group structure between A and B. Rigorously, for all objects x, y of data type A,

f(plus(x, y)) == plus(f(x), f(y))

Because of the Group structure, it is easy to prove that the following will then also be satisfied:

f(negate(x)) == negate(f(x))
f(zero<A>()) == zero<B>()

Functions with these properties interact nicely with Groups, which is why they are given such a special treatment.

## Variables

constexpr auto boost::hana::minus
Subtract two elements of a group.Specifically, this performs the Monoid operation on the first argument and on the inverse of the second argument, thus being equivalent to: More...

constexpr auto boost::hana::negate
Return the inverse of an element of a group. More...

## Variable Documentation

 constexpr auto boost::hana::minus

#include <boost/hana/fwd/minus.hpp>

Initial value:
= [](auto&& x, auto&& y) -> decltype(auto) {
return tag-dispatched;
}

Subtract two elements of a group.Specifically, this performs the Monoid operation on the first argument and on the inverse of the second argument, thus being equivalent to:

minus(x, y) == plus(x, negate(y))

## Cross-type version of the method

The minus method is "overloaded" to handle distinct data types with certain properties. Specifically, minus is defined for distinct data types A and B such that

1. A and B share a common data type C, as determined by the common metafunction
2. A, B and C are all Groups when taken individually
3. to<C> : A -> B and to<C> : B -> C are Group-embeddings, as determined by the is_embedding metafunction.

The definition of minus for data types satisfying the above properties is obtained by setting

minus(x, y) = minus(to<C>(x), to<C>(y))

## Example

// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
namespace hana = boost::hana;
int main() {
BOOST_HANA_CONSTANT_CHECK(hana::minus(hana::int_c<3>, hana::int_c<5>) == hana::int_c<-2>);
static_assert(hana::minus(1, 2) == -1, "");
}
 constexpr auto boost::hana::negate

#include <boost/hana/fwd/negate.hpp>

Initial value:
= [](auto&& x) -> decltype(auto) {
return tag-dispatched;
}

Return the inverse of an element of a group.

## Example

// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
namespace hana = boost::hana;
int main() {
BOOST_HANA_CONSTANT_CHECK(hana::negate(hana::int_c<3>) == hana::int_c<-3>);
static_assert(hana::negate(2) == -2, "");
}