Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: /// \file utility.hpp Chris@16: /// Proto callables for things found in the std \ header Chris@16: // Chris@16: // Copyright 2010 Eric Niebler. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_PROTO_FUNCTIONAL_STD_UTILITY_HPP_EAN_11_27_2010 Chris@16: #define BOOST_PROTO_FUNCTIONAL_STD_UTILITY_HPP_EAN_11_27_2010 Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace proto { namespace functional Chris@16: { Chris@16: /// \brief A PolymorphicFunctionObject type that invokes the Chris@16: /// \c std::make_pair() algorithm on its arguments. Chris@16: /// Chris@16: /// A PolymorphicFunctionObject type that invokes the Chris@16: /// \c std::make_pair() algorithm on its arguments. Chris@16: struct make_pair Chris@16: { Chris@16: BOOST_PROTO_CALLABLE() Chris@16: Chris@16: template Chris@16: struct result; Chris@16: Chris@16: template Chris@16: struct result Chris@16: { Chris@16: typedef Chris@16: std::pair< Chris@16: typename remove_const::type>::type Chris@16: , typename remove_const::type>::type Chris@16: > Chris@16: type; Chris@16: }; Chris@16: Chris@16: template Chris@16: std::pair operator()(First const &first, Second const &second) const Chris@16: { Chris@16: return std::make_pair(first, second); Chris@16: } Chris@16: }; Chris@16: Chris@16: /// \brief A PolymorphicFunctionObject type that returns Chris@16: /// the first element of a std::pair. Chris@16: /// Chris@16: /// A PolymorphicFunctionObject type that returns Chris@16: /// the first element of a std::pair.. Chris@16: struct first Chris@16: { Chris@16: BOOST_PROTO_CALLABLE() Chris@16: Chris@16: template Chris@16: struct result; Chris@16: Chris@16: template Chris@16: struct result Chris@16: { Chris@16: typedef typename Pair::first_type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct result Chris@16: { Chris@16: typedef typename Pair::first_type &type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct result Chris@16: { Chris@16: typedef typename Pair::first_type const &type; Chris@16: }; Chris@16: Chris@16: template Chris@16: typename Pair::first_type &operator()(Pair &pair) const Chris@16: { Chris@16: return pair.first; Chris@16: } Chris@16: Chris@16: template Chris@16: typename Pair::first_type const &operator()(Pair const &pair) const Chris@16: { Chris@16: return pair.first; Chris@16: } Chris@16: }; Chris@16: Chris@16: /// \brief A PolymorphicFunctionObject type that returns Chris@16: /// the second element of a std::pair. Chris@16: /// Chris@16: /// A PolymorphicFunctionObject type that returns Chris@16: /// the second element of a std::pair.. Chris@16: struct second Chris@16: { Chris@16: BOOST_PROTO_CALLABLE() Chris@16: Chris@16: template Chris@16: struct result; Chris@16: Chris@16: template Chris@16: struct result Chris@16: { Chris@16: typedef typename Pair::second_type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct result Chris@16: { Chris@16: typedef typename Pair::second_type &type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct result Chris@16: { Chris@16: typedef typename Pair::second_type const &type; Chris@16: }; Chris@16: Chris@16: template Chris@16: typename Pair::second_type &operator()(Pair &pair) const Chris@16: { Chris@16: return pair.second; Chris@16: } Chris@16: Chris@16: template Chris@16: typename Pair::second_type const &operator()(Pair const &pair) const Chris@16: { Chris@16: return pair.second; Chris@16: } Chris@16: }; Chris@16: Chris@16: }}} Chris@16: Chris@16: #endif