reverse.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #ifndef BOOST_PROTO_FUNCTIONAL_FUSION_REVERSE_HPP_EAN_11_27_2010
  9. #define BOOST_PROTO_FUNCTIONAL_FUSION_REVERSE_HPP_EAN_11_27_2010
  10. #include <boost/fusion/include/reverse.hpp>
  11. #include <boost/proto/proto_fwd.hpp>
  12. namespace boost { namespace proto { namespace functional
  13. {
  14. /// \brief A PolymorphicFunctionObject type that invokes the
  15. /// \c fusion::reverse() algorithm on its argument.
  16. ///
  17. /// A PolymorphicFunctionObject type that invokes the
  18. /// \c fusion::reverse() algorithm on its argument. This is
  19. /// useful for defining a CallableTransform like \c reverse(_)
  20. /// which reverses the order of the children of a Proto
  21. /// expression node.
  22. struct reverse
  23. {
  24. BOOST_PROTO_CALLABLE()
  25. template<typename Sig>
  26. struct result;
  27. template<typename This, typename Seq>
  28. struct result<This(Seq)>
  29. : result<This(Seq const &)>
  30. {};
  31. template<typename This, typename Seq>
  32. struct result<This(Seq &)>
  33. : fusion::result_of::reverse<Seq>
  34. {};
  35. template<typename Seq>
  36. typename fusion::result_of::reverse<Seq>::type
  37. operator ()(Seq &seq) const
  38. {
  39. // Work around a const-correctness issue in Fusion
  40. typedef typename fusion::result_of::reverse<Seq>::type result_type;
  41. return result_type(seq);
  42. }
  43. template<typename Seq>
  44. typename fusion::result_of::reverse<Seq const>::type
  45. operator ()(Seq const &seq) const
  46. {
  47. return fusion::reverse(seq);
  48. }
  49. };
  50. }}}
  51. #endif