Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:57

0001 /*!
0002 @file
0003 Adapts `std::pair` for use with Hana.
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_EXT_STD_PAIR_HPP
0011 #define BOOST_HANA_EXT_STD_PAIR_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/fwd/core/make.hpp>
0015 #include <boost/hana/fwd/core/tag_of.hpp>
0016 #include <boost/hana/fwd/first.hpp>
0017 #include <boost/hana/fwd/second.hpp>
0018 
0019 #include <utility>
0020 
0021 
0022 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0023 namespace std {
0024     //! @ingroup group-ext-std
0025     //! Adaptation of `std::pair` for Hana.
0026     //!
0027     //!
0028     //! Modeled concepts
0029     //! ----------------
0030     //! A `std::pair` models exactly the same concepts as a `hana::pair`.
0031     //! Please refer to the documentation of `hana::pair` for details.
0032     //!
0033     //! @include example/ext/std/pair.cpp
0034     template <typename First, typename Second>
0035     struct pair { };
0036 }
0037 #endif
0038 
0039 
0040 namespace boost { namespace hana {
0041     namespace ext { namespace std { struct pair_tag; }}
0042 
0043     template <typename First, typename Second>
0044     struct tag_of<std::pair<First, Second>> {
0045         using type = ext::std::pair_tag;
0046     };
0047 
0048     //////////////////////////////////////////////////////////////////////////
0049     // Product
0050     //////////////////////////////////////////////////////////////////////////
0051     template <>
0052     struct make_impl<ext::std::pair_tag> {
0053         template <typename X, typename Y>
0054         static constexpr decltype(auto) apply(X&& x, Y&& y) {
0055             return std::make_pair(static_cast<X&&>(x),
0056                                   static_cast<Y&&>(y));
0057         }
0058     };
0059 
0060     template <>
0061     struct first_impl<ext::std::pair_tag> {
0062         template <typename T, typename U>
0063         static constexpr T const& apply(std::pair<T, U> const& p)
0064         {  return p.first; }
0065 
0066         template <typename T, typename U>
0067         static constexpr T& apply(std::pair<T, U>& p)
0068         {  return p.first; }
0069 
0070         template <typename T, typename U>
0071         static constexpr T&& apply(std::pair<T, U>&& p)
0072         {  return static_cast<T&&>(p.first); }
0073     };
0074 
0075     template <>
0076     struct second_impl<ext::std::pair_tag> {
0077         template <typename T, typename U>
0078         static constexpr U const& apply(std::pair<T, U> const& p)
0079         {  return p.second; }
0080 
0081         template <typename T, typename U>
0082         static constexpr U& apply(std::pair<T, U>& p)
0083         {  return p.second; }
0084 
0085         template <typename T, typename U>
0086         static constexpr U&& apply(std::pair<T, U>&& p)
0087         {  return static_cast<U&&>(p.second); }
0088     };
0089 }} // end namespace boost::hana
0090 
0091 #endif // !BOOST_HANA_EXT_STD_PAIR_HPP