Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / accumulators / numeric / detail / function1.hpp @ 2486

History | View | Annotate | Download (2.6 kB)

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