pop_front.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ///////////////////////////////////////////////////////////////////////////////
  2. /// \file pop_front.hpp
  3. /// Proto callables Fusion pop_front
  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_POP_FRONT_HPP_EAN_11_27_2010
  9. #define BOOST_PROTO_FUNCTIONAL_FUSION_POP_FRONT_HPP_EAN_11_27_2010
  10. #include <boost/fusion/include/begin.hpp>
  11. #include <boost/fusion/include/end.hpp>
  12. #include <boost/fusion/include/next.hpp>
  13. #include <boost/fusion/include/pop_front.hpp>
  14. #include <boost/proto/proto_fwd.hpp>
  15. namespace boost { namespace proto { namespace functional
  16. {
  17. /// \brief A PolymorphicFunctionObject type that invokes the
  18. /// \c fusion::pop_front() algorithm on its argument.
  19. ///
  20. /// A PolymorphicFunctionObject type that invokes the
  21. /// \c fusion::pop_front() algorithm on its argument. This is
  22. /// useful for defining a CallableTransform like \c pop_front(_)
  23. /// which removes the first child from a Proto expression node.
  24. /// Such a transform might be used as the first argument to the
  25. /// \c proto::fold\<\> transform; that is, fold all but
  26. /// the first child.
  27. struct pop_front
  28. {
  29. BOOST_PROTO_CALLABLE()
  30. template<typename Sig>
  31. struct result;
  32. template<typename This, typename Seq>
  33. struct result<This(Seq)>
  34. : result<This(Seq const &)>
  35. {};
  36. template<typename This, typename Seq>
  37. struct result<This(Seq &)>
  38. : fusion::result_of::pop_front<Seq>
  39. {};
  40. template<typename Seq>
  41. typename fusion::result_of::pop_front<Seq>::type
  42. operator ()(Seq &seq) const
  43. {
  44. // Work around a const-correctness issue in Fusion
  45. typedef typename fusion::result_of::pop_front<Seq>::type result_type;
  46. return result_type(fusion::next(fusion::begin(seq)), fusion::end(seq));
  47. }
  48. template<typename Seq>
  49. typename fusion::result_of::pop_front<Seq const>::type
  50. operator ()(Seq const &seq) const
  51. {
  52. return fusion::pop_front(seq);
  53. }
  54. };
  55. }}}
  56. #endif