Chris@16
|
1 // Copyright David Abrahams 2006. Distributed under the Boost
|
Chris@16
|
2 // Software License, Version 1.0. (See accompanying
|
Chris@16
|
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
4 #ifndef BOOST_DETAIL_FUNCTION1_DWA200655_HPP
|
Chris@16
|
5 # define BOOST_DETAIL_FUNCTION1_DWA200655_HPP
|
Chris@16
|
6
|
Chris@16
|
7 # include <boost/concept_check.hpp>
|
Chris@16
|
8 # include <boost/type_traits/remove_reference.hpp>
|
Chris@16
|
9 # include <boost/type_traits/add_const.hpp>
|
Chris@16
|
10 # include <boost/mpl/apply.hpp>
|
Chris@16
|
11
|
Chris@16
|
12 namespace boost { namespace detail {
|
Chris@16
|
13
|
Chris@16
|
14 // A utility for creating unary function objects that play nicely with
|
Chris@16
|
15 // boost::result_of and that handle the forwarding problem.
|
Chris@16
|
16 //
|
Chris@16
|
17 // mpl::apply<F, A0>::type is expected to be a stateless function
|
Chris@16
|
18 // object that accepts an argument of type A0&. It is also expected
|
Chris@16
|
19 // to have a nested ::result_type identical to its return type.
|
Chris@16
|
20 template<typename F>
|
Chris@16
|
21 struct function1
|
Chris@16
|
22 {
|
Chris@16
|
23 template<typename Signature>
|
Chris@16
|
24 struct result
|
Chris@16
|
25 {};
|
Chris@16
|
26
|
Chris@16
|
27 template<typename This, typename A0>
|
Chris@16
|
28 struct result<This(A0)>
|
Chris@16
|
29 {
|
Chris@16
|
30 // How adding const to arguments handles rvalues.
|
Chris@16
|
31 //
|
Chris@16
|
32 // if A0 is arg0 is represents actual argument
|
Chris@16
|
33 // -------- ------- --------------------------
|
Chris@16
|
34 // T const & T const const T lvalue
|
Chris@16
|
35 // T & T non-const T lvalue
|
Chris@16
|
36 // T const T const const T rvalue
|
Chris@16
|
37 // T T const non-const T rvalue
|
Chris@16
|
38 typedef typename remove_reference<
|
Chris@16
|
39 typename add_const< A0 >::type
|
Chris@16
|
40 >::type arg0;
|
Chris@16
|
41
|
Chris@16
|
42 typedef typename mpl::apply1<F, arg0>::type impl;
|
Chris@16
|
43 typedef typename impl::result_type type;
|
Chris@16
|
44 };
|
Chris@16
|
45
|
Chris@16
|
46 // Handles mutable lvalues
|
Chris@16
|
47 template<typename A0>
|
Chris@16
|
48 typename result<function1(A0 &)>::type
|
Chris@16
|
49 operator ()(A0 &a0) const
|
Chris@16
|
50 {
|
Chris@16
|
51 typedef typename result<function1(A0 &)>::impl impl;
|
Chris@16
|
52 typedef typename result<function1(A0 &)>::type type;
|
Chris@16
|
53 typedef A0 &arg0;
|
Chris@16
|
54 BOOST_CONCEPT_ASSERT((UnaryFunction<impl, type, arg0>));
|
Chris@16
|
55 //boost::function_requires<UnaryFunctionConcept<impl, type, arg0> >();
|
Chris@16
|
56 return impl()(a0);
|
Chris@16
|
57 }
|
Chris@16
|
58
|
Chris@16
|
59 // Handles const lvalues and all rvalues
|
Chris@16
|
60 template<typename A0>
|
Chris@16
|
61 typename result<function1(A0 const &)>::type
|
Chris@16
|
62 operator ()(A0 const &a0) const
|
Chris@16
|
63 {
|
Chris@16
|
64 typedef typename result<function1(A0 const &)>::impl impl;
|
Chris@16
|
65 typedef typename result<function1(A0 const &)>::type type;
|
Chris@16
|
66 typedef A0 const &arg0;
|
Chris@16
|
67 BOOST_CONCEPT_ASSERT((UnaryFunction<impl, type, arg0>));
|
Chris@16
|
68 //boost::function_requires<UnaryFunctionConcept<impl, type, arg0> >();
|
Chris@16
|
69 return impl()(a0);
|
Chris@16
|
70 }
|
Chris@16
|
71 };
|
Chris@16
|
72
|
Chris@16
|
73 }} // namespace boost::detail
|
Chris@16
|
74
|
Chris@16
|
75 #endif // BOOST_DETAIL_FUNCTION1_DWA200655_HPP
|