Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:53:04

0001 /*!
0002 @file
0003 Forward declares `boost::hana::pair`.
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_PAIR_HPP
0011 #define BOOST_HANA_FWD_PAIR_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/fwd/core/make.hpp>
0015 
0016 
0017 namespace boost { namespace hana {
0018     //! @ingroup group-datatypes
0019     //! Generic container for two elements.
0020     //!
0021     //! `hana::pair` is conceptually the same as `std::pair`. However,
0022     //! `hana::pair` automatically compresses the storage of empty types,
0023     //! and as a result it does not have the `.first` and `.second` members.
0024     //! Instead, one must use the `hana::first` and `hana::second` free
0025     //! functions to access the elements of a pair.
0026     //!
0027     //! @note
0028     //! When you use a container, remember not to make assumptions about its
0029     //! representation, unless the documentation gives you those guarantees.
0030     //! More details [in the tutorial](@ref tutorial-containers-types).
0031     //!
0032     //!
0033     //! Modeled concepts
0034     //! ----------------
0035     //! 1. `Comparable`\n
0036     //! Two pairs `(x, y)` and `(x', y')` are equal if and only if both
0037     //! `x == x'` and `y == y'`.
0038     //! @include example/pair/comparable.cpp
0039     //!
0040     //! 2. `Orderable`\n
0041     //! Pairs are ordered as-if they were 2-element tuples, using a
0042     //! lexicographical ordering.
0043     //! @include example/pair/orderable.cpp
0044     //!
0045     //! 3. `Foldable`\n
0046     //! Folding a pair is equivalent to folding a 2-element tuple. In other
0047     //! words:
0048     //! @code
0049     //!     fold_left(make_pair(x, y), s, f) == f(f(s, x), y)
0050     //!     fold_right(make_pair(x, y), s, f) == f(x, f(y, s))
0051     //! @endcode
0052     //! Example:
0053     //! @include example/pair/foldable.cpp
0054     //!
0055     //! 4. `Product`\n
0056     //! The model of `Product` is the simplest one possible; the first element
0057     //! of a pair `(x, y)` is `x`, and its second element is `y`.
0058     //! @include example/pair/product.cpp
0059 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0060     template <typename First, typename Second>
0061     struct pair {
0062         //! Default constructs the `pair`. Only exists when both elements
0063         //! of the pair are default constructible.
0064         constexpr pair();
0065 
0066         //! Initialize each element of the pair with the corresponding element.
0067         //! Only exists when both elements of the pair are copy-constructible.
0068         constexpr pair(First const& first, Second const& second);
0069 
0070         //! Initialize both elements of the pair by perfect-forwarding the
0071         //! corresponding argument. Only exists when both arguments are
0072         //! implicitly-convertible to the corresponding element of the pair.
0073         template <typename T, typename U>
0074         constexpr pair(T&& t, U&& u);
0075 
0076         //! Copy-initialize a pair from another pair. Only exists when both
0077         //! elements of the source pair are implicitly convertible to the
0078         //! corresponding element of the constructed pair.
0079         template <typename T, typename U>
0080         constexpr pair(pair<T, U> const& other);
0081 
0082         //! Move-initialize a pair from another pair. Only exists when both
0083         //! elements of the source pair are implicitly convertible to the
0084         //! corresponding element of the constructed pair.
0085         template <typename T, typename U>
0086         constexpr pair(pair<T, U>&& other);
0087 
0088         //! Assign a pair to another pair. Only exists when both elements
0089         //! of the destination pair are assignable from the corresponding
0090         //! element in the source pair.
0091         template <typename T, typename U>
0092         constexpr pair& operator=(pair<T, U> const& other);
0093 
0094         //! Move-assign a pair to another pair. Only exists when both elements
0095         //! of the destination pair are move-assignable from the corresponding
0096         //! element in the source pair.
0097         template <typename T, typename U>
0098         constexpr pair& operator=(pair<T, U>&& other);
0099 
0100         //! Equivalent to `hana::equal`
0101         template <typename X, typename Y>
0102         friend constexpr auto operator==(X&& x, Y&& y);
0103 
0104         //! Equivalent to `hana::not_equal`
0105         template <typename X, typename Y>
0106         friend constexpr auto operator!=(X&& x, Y&& y);
0107 
0108         //! Equivalent to `hana::less`
0109         template <typename X, typename Y>
0110         friend constexpr auto operator<(X&& x, Y&& y);
0111 
0112         //! Equivalent to `hana::greater`
0113         template <typename X, typename Y>
0114         friend constexpr auto operator>(X&& x, Y&& y);
0115 
0116         //! Equivalent to `hana::less_equal`
0117         template <typename X, typename Y>
0118         friend constexpr auto operator<=(X&& x, Y&& y);
0119 
0120         //! Equivalent to `hana::greater_equal`
0121         template <typename X, typename Y>
0122         friend constexpr auto operator>=(X&& x, Y&& y);
0123     };
0124 #else
0125     template <typename First, typename Second>
0126     struct pair;
0127 #endif
0128 
0129     //! Tag representing `hana::pair`.
0130     //! @relates hana::pair
0131     struct pair_tag { };
0132 
0133 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0134     //! Creates a `hana::pair` with the given elements.
0135     //! @relates hana::pair
0136     //!
0137     //!
0138     //! Example
0139     //! -------
0140     //! @include example/pair/make.cpp
0141     template <>
0142     constexpr auto make<pair_tag> = [](auto&& first, auto&& second)
0143         -> hana::pair<std::decay_t<decltype(first)>, std::decay_t<decltype(second)>>
0144     {
0145         return {forwarded(first), forwarded(second)};
0146     };
0147 #endif
0148 
0149     //! Alias to `make<pair_tag>`; provided for convenience.
0150     //! @relates hana::pair
0151     //!
0152     //! Example
0153     //! -------
0154     //! @include example/pair/make.cpp
0155     BOOST_HANA_INLINE_VARIABLE constexpr auto make_pair = make<pair_tag>;
0156 }} // end namespace boost::hana
0157 
0158 #endif // !BOOST_HANA_FWD_PAIR_HPP