// Copyright David Abrahams 2006. Distributed under the Boost // Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_DETAIL_FUNCTION1_DWA200655_HPP # define BOOST_DETAIL_FUNCTION1_DWA200655_HPP # include # include # include # include namespace boost { namespace detail { // A utility for creating unary function objects that play nicely with // boost::result_of and that handle the forwarding problem. // // mpl::apply::type is expected to be a stateless function // object that accepts an argument of type A0&. It is also expected // to have a nested ::result_type identical to its return type. template struct function1 { template struct result {}; template struct result { // How adding const to arguments handles rvalues. // // if A0 is arg0 is represents actual argument // -------- ------- -------------------------- // T const & T const const T lvalue // T & T non-const T lvalue // T const T const const T rvalue // T T const non-const T rvalue typedef typename remove_reference< typename add_const< A0 >::type >::type arg0; typedef typename mpl::apply1::type impl; typedef typename impl::result_type type; }; // Handles mutable lvalues template typename result::type operator ()(A0 &a0) const { typedef typename result::impl impl; typedef typename result::type type; typedef A0 &arg0; BOOST_CONCEPT_ASSERT((UnaryFunction)); //boost::function_requires >(); return impl()(a0); } // Handles const lvalues and all rvalues template typename result::type operator ()(A0 const &a0) const { typedef typename result::impl impl; typedef typename result::type type; typedef A0 const &arg0; BOOST_CONCEPT_ASSERT((UnaryFunction)); //boost::function_requires >(); return impl()(a0); } }; }} // namespace boost::detail #endif // BOOST_DETAIL_FUNCTION1_DWA200655_HPP