Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:27

0001 ///////////////////////////////////////////////////////////////////////////////
0002 /// \file utility.hpp
0003 /// Proto callables for things found in the std \<utility\> header
0004 //
0005 //  Copyright 2010 Eric Niebler. Distributed under the Boost
0006 //  Software License, Version 1.0. (See accompanying file
0007 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #ifndef BOOST_PROTO_FUNCTIONAL_STD_UTILITY_HPP_EAN_11_27_2010
0010 #define BOOST_PROTO_FUNCTIONAL_STD_UTILITY_HPP_EAN_11_27_2010
0011 
0012 #include <utility>
0013 #include <boost/type_traits/remove_const.hpp>
0014 #include <boost/type_traits/remove_reference.hpp>
0015 #include <boost/proto/proto_fwd.hpp>
0016 
0017 namespace boost { namespace proto { namespace functional
0018 {
0019     /// \brief A PolymorphicFunctionObject type that invokes the
0020     /// \c std::make_pair() algorithm on its arguments.
0021     ///
0022     /// A PolymorphicFunctionObject type that invokes the
0023     /// \c std::make_pair() algorithm on its arguments.
0024     struct make_pair
0025     {
0026         BOOST_PROTO_CALLABLE()
0027 
0028         template<typename Sig>
0029         struct result;
0030 
0031         template<typename This, typename First, typename Second>
0032         struct result<This(First, Second)>
0033         {
0034             typedef
0035                 std::pair<
0036                     typename remove_const<typename remove_reference<First>::type>::type
0037                   , typename remove_const<typename remove_reference<Second>::type>::type
0038                 >
0039             type;
0040         };
0041 
0042         template<typename First, typename Second>
0043         std::pair<First, Second> operator()(First const &first, Second const &second) const
0044         {
0045             return std::make_pair(first, second);
0046         }
0047     };
0048 
0049     /// \brief A PolymorphicFunctionObject type that returns
0050     /// the first element of a std::pair.
0051     ///
0052     /// A PolymorphicFunctionObject type that returns
0053     /// the first element of a std::pair..
0054     struct first
0055     {
0056         BOOST_PROTO_CALLABLE()
0057 
0058         template<typename Sig>
0059         struct result;
0060 
0061         template<typename This, typename Pair>
0062         struct result<This(Pair)>
0063         {
0064             typedef typename Pair::first_type type;
0065         };
0066 
0067         template<typename This, typename Pair>
0068         struct result<This(Pair &)>
0069         {
0070             typedef typename Pair::first_type &type;
0071         };
0072 
0073         template<typename This, typename Pair>
0074         struct result<This(Pair const &)>
0075         {
0076             typedef typename Pair::first_type const &type;
0077         };
0078 
0079         template<typename Pair>
0080         typename Pair::first_type &operator()(Pair &pair) const
0081         {
0082             return pair.first;
0083         }
0084 
0085         template<typename Pair>
0086         typename Pair::first_type const &operator()(Pair const &pair) const
0087         {
0088             return pair.first;
0089         }
0090     };
0091 
0092     /// \brief A PolymorphicFunctionObject type that returns
0093     /// the second element of a std::pair.
0094     ///
0095     /// A PolymorphicFunctionObject type that returns
0096     /// the second element of a std::pair..
0097     struct second
0098     {
0099         BOOST_PROTO_CALLABLE()
0100 
0101         template<typename Sig>
0102         struct result;
0103 
0104         template<typename This, typename Pair>
0105         struct result<This(Pair)>
0106         {
0107             typedef typename Pair::second_type type;
0108         };
0109 
0110         template<typename This, typename Pair>
0111         struct result<This(Pair &)>
0112         {
0113             typedef typename Pair::second_type &type;
0114         };
0115 
0116         template<typename This, typename Pair>
0117         struct result<This(Pair const &)>
0118         {
0119             typedef typename Pair::second_type const &type;
0120         };
0121 
0122         template<typename Pair>
0123         typename Pair::second_type &operator()(Pair &pair) const
0124         {
0125             return pair.second;
0126         }
0127 
0128         template<typename Pair>
0129         typename Pair::second_type const &operator()(Pair const &pair) const
0130         {
0131             return pair.second;
0132         }
0133     };
0134 
0135 }}}
0136 
0137 #endif