Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:58

0001 /*!
0002 @file
0003 Forward declares `boost::hana::Monoid`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_FWD_CONCEPT_MONOID_HPP
0011 #define BOOST_HANA_FWD_CONCEPT_MONOID_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 
0015 
0016 namespace boost { namespace hana {
0017     //! @ingroup group-concepts
0018     //! @defgroup group-Monoid Monoid
0019     //! The `Monoid` concept represents data types with an associative
0020     //! binary operation that has an identity.
0021     //!
0022     //! Specifically, a [Monoid][1] is a basic algebraic structure typically
0023     //! used in mathematics to construct more complex algebraic structures
0024     //! like `Group`s, `Ring`s and so on. They are useful in several contexts,
0025     //! notably to define the properties of numbers in a granular way. At its
0026     //! core, a `Monoid` is a set `S` of objects along with a binary operation
0027     //! (let's say `+`) that is associative and that has an identity in `S`.
0028     //! There are many examples of `Monoid`s:
0029     //! - strings with concatenation and the empty string as the identity
0030     //! - integers with addition and `0` as the identity
0031     //! - integers with multiplication and `1` as the identity
0032     //! - many others...
0033     //!
0034     //! As you can see with the integers, there are some sets that can be
0035     //! viewed as a monoid in more than one way, depending on the choice
0036     //! of the binary operation and identity. The method names used here
0037     //! refer to the monoid of integers under addition; `plus` is the binary
0038     //! operation and `zero` is the identity element of that operation.
0039     //!
0040     //!
0041     //! Minimal complete definition
0042     //! ---------------------------
0043     //! `plus` and `zero` satisfying the laws
0044     //!
0045     //!
0046     //! Laws
0047     //! ----
0048     //! For all objects `x`, `y` and `z` of a `Monoid` `M`, the following
0049     //! laws must be satisfied:
0050     //! @code
0051     //!     plus(zero<M>(), x) == x                    // left zero
0052     //!     plus(x, zero<M>()) == x                    // right zero
0053     //!     plus(x, plus(y, z)) == plus(plus(x, y), z) // associativity
0054     //! @endcode
0055     //!
0056     //!
0057     //! Concrete models
0058     //! ---------------
0059     //! `hana::integral_constant`
0060     //!
0061     //!
0062     //! Free model for non-boolean arithmetic data types
0063     //! ------------------------------------------------
0064     //! A data type `T` is arithmetic if `std::is_arithmetic<T>::%value` is
0065     //! true. For a non-boolean arithmetic data type `T`, a model of `Monoid`
0066     //! is automatically defined by setting
0067     //! @code
0068     //!     plus(x, y) = (x + y)
0069     //!     zero<T>() = static_cast<T>(0)
0070     //! @endcode
0071     //!
0072     //! > #### Rationale for not making `bool` a `Monoid` by default
0073     //! > First, it makes no sense whatsoever to define an additive `Monoid`
0074     //! > over the `bool` type. Also, it could make sense to define a `Monoid`
0075     //! > with logical conjunction or disjunction. However, C++ allows `bool`s
0076     //! > to be added, and the method names of this concept really suggest
0077     //! > addition. In line with the principle of least surprise, no model
0078     //! > is provided by default.
0079     //!
0080     //!
0081     //! Structure-preserving functions
0082     //! ------------------------------
0083     //! Let `A` and `B` be two `Monoid`s. A function `f : A -> B` is said
0084     //! to be a [Monoid morphism][2] if it preserves the monoidal structure
0085     //! between `A` and `B`. Rigorously, for all objects `x, y` of data
0086     //! type `A`,
0087     //! @code
0088     //!     f(plus(x, y)) == plus(f(x), f(y))
0089     //!     f(zero<A>()) == zero<B>()
0090     //! @endcode
0091     //! Functions with these properties interact nicely with `Monoid`s, which
0092     //! is why they are given such a special treatment.
0093     //!
0094     //!
0095     //! [1]: http://en.wikipedia.org/wiki/Monoid
0096     //! [2]: http://en.wikipedia.org/wiki/Monoid#Monoid_homomorphisms
0097     template <typename M>
0098     struct Monoid;
0099 }} // end namespace boost::hana
0100 
0101 #endif // !BOOST_HANA_FWD_CONCEPT_MONOID_HPP