Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:19

0001 // Copyright David Abrahams 2006. Distributed under the Boost
0002 // Software License, Version 1.0. (See accompanying
0003 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0004 #ifndef BOOST_DETAIL_FUNCTION1_DWA200655_HPP
0005 # define BOOST_DETAIL_FUNCTION1_DWA200655_HPP
0006 
0007 # include <boost/concept_check.hpp>
0008 # include <boost/type_traits/remove_reference.hpp>
0009 # include <boost/type_traits/add_const.hpp>
0010 # include <boost/mpl/apply.hpp>
0011 
0012 namespace boost { namespace detail {
0013 
0014 // A utility for creating unary function objects that play nicely with
0015 // boost::result_of and that handle the forwarding problem.
0016 //
0017 // mpl::apply<F, A0>::type is expected to be a stateless function
0018 // object that accepts an argument of type A0&.  It is also expected
0019 // to have a nested ::result_type identical to its return type.
0020 template<typename F>
0021 struct function1
0022 {
0023     template<typename Signature>
0024     struct result
0025     {};
0026 
0027     template<typename This, typename A0>
0028     struct result<This(A0)>
0029     {
0030         // How adding const to arguments handles rvalues.
0031         //
0032         // if A0 is     arg0 is       represents actual argument
0033         // --------     -------       --------------------------
0034         // T const &    T const       const T lvalue
0035         // T &          T             non-const T lvalue
0036         // T const      T const       const T rvalue
0037         // T            T const       non-const T rvalue
0038         typedef typename remove_reference<
0039             typename add_const< A0 >::type
0040         >::type arg0;
0041 
0042         typedef typename mpl::apply1<F, arg0>::type impl;
0043         typedef typename impl::result_type type;
0044     };
0045 
0046     // Handles mutable lvalues
0047     template<typename A0>
0048     typename result<function1(A0 &)>::type
0049     operator ()(A0 &a0) const
0050     {
0051         typedef typename result<function1(A0 &)>::impl impl;
0052         typedef typename result<function1(A0 &)>::type type;
0053         typedef A0 &arg0;
0054         BOOST_CONCEPT_ASSERT((UnaryFunction<impl, type, arg0>));
0055         //boost::function_requires<UnaryFunctionConcept<impl, type, arg0> >();
0056         return impl()(a0);
0057     }
0058 
0059     // Handles const lvalues and all rvalues
0060     template<typename A0>
0061     typename result<function1(A0 const &)>::type
0062     operator ()(A0 const &a0) const
0063     {
0064         typedef typename result<function1(A0 const &)>::impl impl;
0065         typedef typename result<function1(A0 const &)>::type type;
0066         typedef A0 const &arg0;
0067         BOOST_CONCEPT_ASSERT((UnaryFunction<impl, type, arg0>));
0068         //boost::function_requires<UnaryFunctionConcept<impl, type, arg0> >();
0069         return impl()(a0);
0070     }
0071 };
0072 
0073 }} // namespace boost::detail
0074 
0075 #endif // BOOST_DETAIL_FUNCTION1_DWA200655_HPP