]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/hana/fwd/pair.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / hana / fwd / pair.hpp
1 /*!
2 @file
3 Forward declares `boost::hana::pair`.
4
5 @copyright Louis Dionne 2013-2017
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
8 */
9
10 #ifndef BOOST_HANA_FWD_PAIR_HPP
11 #define BOOST_HANA_FWD_PAIR_HPP
12
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/fwd/core/make.hpp>
15
16
17 namespace boost { namespace hana {
18 //! @ingroup group-datatypes
19 //! Generic container for two elements.
20 //!
21 //! `hana::pair` is conceptually the same as `std::pair`. However,
22 //! `hana::pair` automatically compresses the storage of empty types,
23 //! and as a result it does not have the `.first` and `.second` members.
24 //! Instead, one must use the `hana::first` and `hana::second` free
25 //! functions to access the elements of a pair.
26 //!
27 //! @note
28 //! When you use a container, remember not to make assumptions about its
29 //! representation, unless the documentation gives you those guarantees.
30 //! More details [in the tutorial](@ref tutorial-containers-types).
31 //!
32 //!
33 //! Modeled concepts
34 //! ----------------
35 //! 1. `Comparable`\n
36 //! Two pairs `(x, y)` and `(x', y')` are equal if and only if both
37 //! `x == x'` and `y == y'`.
38 //! @include example/pair/comparable.cpp
39 //!
40 //! 2. `Orderable`\n
41 //! Pairs are ordered as-if they were 2-element tuples, using a
42 //! lexicographical ordering.
43 //! @include example/pair/orderable.cpp
44 //!
45 //! 3. `Foldable`\n
46 //! Folding a pair is equivalent to folding a 2-element tuple. In other
47 //! words:
48 //! @code
49 //! fold_left(make_pair(x, y), s, f) == f(f(s, x), y)
50 //! fold_right(make_pair(x, y), s, f) == f(x, f(y, s))
51 //! @endcode
52 //! Example:
53 //! @include example/pair/foldable.cpp
54 //!
55 //! 4. `Product`\n
56 //! The model of `Product` is the simplest one possible; the first element
57 //! of a pair `(x, y)` is `x`, and its second element is `y`.
58 //! @include example/pair/product.cpp
59 #ifdef BOOST_HANA_DOXYGEN_INVOKED
60 template <typename First, typename Second>
61 struct pair {
62 //! Default constructs the `pair`. Only exists when both elements
63 //! of the pair are default constructible.
64 constexpr pair();
65
66 //! Initialize each element of the pair with the corresponding element.
67 //! Only exists when both elements of the pair are copy-constructible.
68 constexpr pair(First const& first, Second const& second);
69
70 //! Initialize both elements of the pair by perfect-forwarding the
71 //! corresponding argument. Only exists when both arguments are
72 //! implicitly-convertible to the corresponding element of the pair.
73 template <typename T, typename U>
74 constexpr pair(T&& t, U&& u);
75
76 //! Copy-initialize a pair from another pair. Only exists when both
77 //! elements of the source pair are implicitly convertible to the
78 //! corresponding element of the constructed pair.
79 template <typename T, typename U>
80 constexpr pair(pair<T, U> const& other);
81
82 //! Move-initialize a pair from another pair. Only exists when both
83 //! elements of the source pair are implicitly convertible to the
84 //! corresponding element of the constructed pair.
85 template <typename T, typename U>
86 constexpr pair(pair<T, U>&& other);
87
88 //! Assign a pair to another pair. Only exists when both elements
89 //! of the destination pair are assignable from the corresponding
90 //! element in the source pair.
91 template <typename T, typename U>
92 constexpr pair& operator=(pair<T, U> const& other);
93
94 //! Move-assign a pair to another pair. Only exists when both elements
95 //! of the destination pair are move-assignable from the corresponding
96 //! element in the source pair.
97 template <typename T, typename U>
98 constexpr pair& operator=(pair<T, U>&& other);
99
100 //! Equivalent to `hana::equal`
101 template <typename X, typename Y>
102 friend constexpr auto operator==(X&& x, Y&& y);
103
104 //! Equivalent to `hana::not_equal`
105 template <typename X, typename Y>
106 friend constexpr auto operator!=(X&& x, Y&& y);
107
108 //! Equivalent to `hana::less`
109 template <typename X, typename Y>
110 friend constexpr auto operator<(X&& x, Y&& y);
111
112 //! Equivalent to `hana::greater`
113 template <typename X, typename Y>
114 friend constexpr auto operator>(X&& x, Y&& y);
115
116 //! Equivalent to `hana::less_equal`
117 template <typename X, typename Y>
118 friend constexpr auto operator<=(X&& x, Y&& y);
119
120 //! Equivalent to `hana::greater_equal`
121 template <typename X, typename Y>
122 friend constexpr auto operator>=(X&& x, Y&& y);
123 };
124 #else
125 template <typename First, typename Second>
126 struct pair;
127 #endif
128
129 //! Tag representing `hana::pair`.
130 //! @relates hana::pair
131 struct pair_tag { };
132
133 #ifdef BOOST_HANA_DOXYGEN_INVOKED
134 //! Creates a `hana::pair` with the given elements.
135 //! @relates hana::pair
136 //!
137 //!
138 //! Example
139 //! -------
140 //! @include example/pair/make.cpp
141 template <>
142 constexpr auto make<pair_tag> = [](auto&& first, auto&& second)
143 -> hana::pair<std::decay_t<decltype(first)>, std::decay_t<decltype(second)>>
144 {
145 return {forwarded(first), forwarded(second)};
146 };
147 #endif
148
149 //! Alias to `make<pair_tag>`; provided for convenience.
150 //! @relates hana::pair
151 //!
152 //! Example
153 //! -------
154 //! @include example/pair/make.cpp
155 BOOST_HANA_INLINE_VARIABLE constexpr auto make_pair = make<pair_tag>;
156 }} // end namespace boost::hana
157
158 #endif // !BOOST_HANA_FWD_PAIR_HPP