1 ///////////////////////////////////////////////////////////////////////////////
2 /// \file reverse.hpp
3 /// Proto callables Fusion reverse
4 //
5 //  Copyright 2010 Eric Niebler. Distributed under the Boost
6 //  Software License, Version 1.0. (See accompanying file
7 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 
9 #ifndef BOOST_PROTO_FUNCTIONAL_FUSION_REVERSE_HPP_EAN_11_27_2010
10 #define BOOST_PROTO_FUNCTIONAL_FUSION_REVERSE_HPP_EAN_11_27_2010
11 
12 #include <boost/fusion/include/reverse.hpp>
13 #include <boost/proto/proto_fwd.hpp>
14 
15 namespace boost { namespace proto { namespace functional
16 {
17     /// \brief A PolymorphicFunctionObject type that invokes the
18     /// \c fusion::reverse() algorithm on its argument.
19     ///
20     /// A PolymorphicFunctionObject type that invokes the
21     /// \c fusion::reverse() algorithm on its argument. This is
22     /// useful for defining a CallableTransform like \c reverse(_)
23     /// which reverses the order of the children of a Proto
24     /// expression node.
25     struct reverse
26     {
27         BOOST_PROTO_CALLABLE()
28 
29         template<typename Sig>
30         struct result;
31 
32         template<typename This, typename Seq>
33         struct result<This(Seq)>
34           : result<This(Seq const &)>
35         {};
36 
37         template<typename This, typename Seq>
38         struct result<This(Seq &)>
39           : fusion::result_of::reverse<Seq>
40         {};
41 
42         template<typename Seq>
43         typename fusion::result_of::reverse<Seq>::type
operator ()boost::proto::functional::reverse44         operator ()(Seq &seq) const
45         {
46             // Work around a const-correctness issue in Fusion
47             typedef typename fusion::result_of::reverse<Seq>::type result_type;
48             return result_type(seq);
49         }
50 
51         template<typename Seq>
52         typename fusion::result_of::reverse<Seq const>::type
operator ()boost::proto::functional::reverse53         operator ()(Seq const &seq) const
54         {
55             return fusion::reverse(seq);
56         }
57     };
58 }}}
59 
60 #endif
61