3 Forward declares `boost::hana::pair`.
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)
10 #ifndef BOOST_HANA_FWD_PAIR_HPP
11 #define BOOST_HANA_FWD_PAIR_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/fwd/core/make.hpp>
17 namespace boost { namespace hana {
18 //! @ingroup group-datatypes
19 //! Generic container for two elements.
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.
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).
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
41 //! Pairs are ordered as-if they were 2-element tuples, using a
42 //! lexicographical ordering.
43 //! @include example/pair/orderable.cpp
46 //! Folding a pair is equivalent to folding a 2-element tuple. In other
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))
53 //! @include example/pair/foldable.cpp
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>
62 //! Default constructs the `pair`. Only exists when both elements
63 //! of the pair are default constructible.
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);
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);
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);
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);
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);
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);
100 //! Equivalent to `hana::equal`
101 template <typename X, typename Y>
102 friend constexpr auto operator==(X&& x, Y&& y);
104 //! Equivalent to `hana::not_equal`
105 template <typename X, typename Y>
106 friend constexpr auto operator!=(X&& x, Y&& y);
108 //! Equivalent to `hana::less`
109 template <typename X, typename Y>
110 friend constexpr auto operator<(X&& x, Y&& y);
112 //! Equivalent to `hana::greater`
113 template <typename X, typename Y>
114 friend constexpr auto operator>(X&& x, Y&& y);
116 //! Equivalent to `hana::less_equal`
117 template <typename X, typename Y>
118 friend constexpr auto operator<=(X&& x, Y&& y);
120 //! Equivalent to `hana::greater_equal`
121 template <typename X, typename Y>
122 friend constexpr auto operator>=(X&& x, Y&& y);
125 template <typename First, typename Second>
129 //! Tag representing `hana::pair`.
130 //! @relates hana::pair
133 #ifdef BOOST_HANA_DOXYGEN_INVOKED
134 //! Creates a `hana::pair` with the given elements.
135 //! @relates hana::pair
140 //! @include example/pair/make.cpp
142 constexpr auto make<pair_tag> = [](auto&& first, auto&& second)
143 -> hana::pair<std::decay_t<decltype(first)>, std::decay_t<decltype(second)>>
145 return {forwarded(first), forwarded(second)};
149 //! Alias to `make<pair_tag>`; provided for convenience.
150 //! @relates hana::pair
154 //! @include example/pair/make.cpp
155 BOOST_HANA_INLINE_VARIABLE constexpr auto make_pair = make<pair_tag>;
156 }} // end namespace boost::hana
158 #endif // !BOOST_HANA_FWD_PAIR_HPP