3 Adapts `std::pair` for use with Hana.
5 @copyright Louis Dionne 2013-2016
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_EXT_STD_PAIR_HPP
11 #define BOOST_HANA_EXT_STD_PAIR_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/fwd/core/make.hpp>
15 #include <boost/hana/fwd/core/tag_of.hpp>
16 #include <boost/hana/fwd/first.hpp>
17 #include <boost/hana/fwd/second.hpp>
22 #ifdef BOOST_HANA_DOXYGEN_INVOKED
24 //! @ingroup group-ext-std
25 //! Adaptation of `std::pair` for Hana.
30 //! A `std::pair` models exactly the same concepts as a `hana::pair`.
31 //! Please refer to the documentation of `hana::pair` for details.
33 //! @include example/ext/std/pair.cpp
34 template <typename First, typename Second>
40 BOOST_HANA_NAMESPACE_BEGIN
41 namespace ext { namespace std { struct pair_tag; }}
43 template <typename First, typename Second>
44 struct tag_of<std::pair<First, Second>> {
45 using type = ext::std::pair_tag;
48 //////////////////////////////////////////////////////////////////////////
50 //////////////////////////////////////////////////////////////////////////
52 struct make_impl<ext::std::pair_tag> {
53 template <typename X, typename Y>
54 static constexpr decltype(auto) apply(X&& x, Y&& y) {
55 return std::make_pair(static_cast<X&&>(x),
61 struct first_impl<ext::std::pair_tag> {
62 template <typename T, typename U>
63 static constexpr T const& apply(std::pair<T, U> const& p)
66 template <typename T, typename U>
67 static constexpr T& apply(std::pair<T, U>& p)
70 template <typename T, typename U>
71 static constexpr T&& apply(std::pair<T, U>&& p)
72 { return static_cast<T&&>(p.first); }
76 struct second_impl<ext::std::pair_tag> {
77 template <typename T, typename U>
78 static constexpr U const& apply(std::pair<T, U> const& p)
81 template <typename T, typename U>
82 static constexpr U& apply(std::pair<T, U>& p)
85 template <typename T, typename U>
86 static constexpr U&& apply(std::pair<T, U>&& p)
87 { return static_cast<U&&>(p.second); }
89 BOOST_HANA_NAMESPACE_END
91 #endif // !BOOST_HANA_EXT_STD_PAIR_HPP