|
||||
File indexing completed on 2025-01-18 09:37:58
0001 /*! 0002 @file 0003 Forward declares `boost::hana::Product`. 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_PRODUCT_HPP 0011 #define BOOST_HANA_FWD_CONCEPT_PRODUCT_HPP 0012 0013 #include <boost/hana/config.hpp> 0014 0015 0016 namespace boost { namespace hana { 0017 //! @ingroup group-concepts 0018 //! @defgroup group-Product Product 0019 //! Represents types that are generic containers of two elements. 0020 //! 0021 //! This concept basically represents types that are like `std::pair`. 0022 //! The motivation for making such a precise concept is similar to the 0023 //! motivation behind the `Sequence` concept; there are many different 0024 //! implementations of `std::pair` in different libraries, and we would 0025 //! like to manipulate any of them generically. 0026 //! 0027 //! Since a `Product` is basically a pair, it is unsurprising that the 0028 //! operations provided by this concept are getting the first and second 0029 //! element of a pair, creating a pair from two elements and other 0030 //! simmilar operations. 0031 //! 0032 //! @note 0033 //! Mathematically, this concept represents types that are category 0034 //! theoretical [products][1]. This is also where the name comes 0035 //! from. 0036 //! 0037 //! 0038 //! Minimal complete definition 0039 //! --------------------------- 0040 //! `first`, `second` and `make` 0041 //! 0042 //! `first` and `second` must obviously return the first and the second 0043 //! element of the pair, respectively. `make` must take two arguments `x` 0044 //! and `y` representing the first and the second element of the pair, 0045 //! and return a pair `p` such that `first(p) == x` and `second(p) == y`. 0046 //! @include example/product/make.cpp 0047 //! 0048 //! 0049 //! Laws 0050 //! ---- 0051 //! For a model `P` of `Product`, the following laws must be satisfied. 0052 //! For every data types `X` and `Y`, there must be a unique function 0053 //! @f$ \mathtt{make} : X \times Y \to P @f$ such that for every `x`, `y`, 0054 //! @code 0055 //! x == first(make<P>(x, y)) 0056 //! y == second(make<P>(x, y)) 0057 //! @endcode 0058 //! 0059 //! @note 0060 //! This law is less general than the universal property typically used to 0061 //! define category theoretical products, but it is vastly enough for what 0062 //! we need. 0063 //! 0064 //! This is basically saying that a `Product` must be the most general 0065 //! object able to contain a pair of objects `(P1, P2)`, but nothing 0066 //! more. Since the categorical product is defined by a universal 0067 //! property, all the models of this concept are isomorphic, and 0068 //! the isomorphism is unique. In other words, there is one and only 0069 //! one way to convert one `Product` to another. 0070 //! 0071 //! Another property that must be satisfied by `first` and `second` is 0072 //! that of @ref move-independence, which ensures that we can optimally 0073 //! decompose a `Product` into its two members without making redundant 0074 //! copies. 0075 //! 0076 //! 0077 //! Refined concepts 0078 //! ---------------- 0079 //! 1. `Comparable` (free model)\n 0080 //! Two products `x` and `y` are equal iff they are equal element-wise, 0081 //! by comparing the first element before the second element. 0082 //! @include example/product/comparable.cpp 0083 //! 0084 //! 2. `Orderable` (free model)\n 0085 //! Products are ordered using a lexicographical ordering as-if they 0086 //! were 2-element tuples. 0087 //! 0088 //! 3. `Foldable` (free model)\n 0089 //! Folding a `Product` `p` is equivalent to folding a list containing 0090 //! `first(p)` and `second(p)`, in that order. 0091 //! 0092 //! 0093 //! Concrete models 0094 //! --------------- 0095 //! `hana::pair` 0096 //! 0097 //! 0098 //! [1]: http://en.wikipedia.org/wiki/Product_(category_theory) 0099 template <typename P> 0100 struct Product; 0101 }} // end namespace boost::hana 0102 0103 #endif // !BOOST_HANA_FWD_CONCEPT_PRODUCT_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |