reverse_cons.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*=============================================================================
  2. Copyright (c) 2011 Eric Niebler
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(BOOST_FUSION_REVERSE_CONS_HPP_INCLUDED)
  7. #define BOOST_FUSION_REVERSE_CONS_HPP_INCLUDED
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/container/list/cons_fwd.hpp>
  10. namespace boost { namespace fusion { namespace detail
  11. {
  12. ////////////////////////////////////////////////////////////////////////////
  13. template<typename Cons, typename State = nil_>
  14. struct reverse_cons;
  15. template<typename Car, typename Cdr, typename State>
  16. struct reverse_cons<cons<Car, Cdr>, State>
  17. {
  18. typedef reverse_cons<Cdr, cons<Car, State> > impl;
  19. typedef typename impl::type type;
  20. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  21. static type call(cons<Car, Cdr> const &cons, State const &state = State())
  22. {
  23. typedef fusion::cons<Car, State> cdr_type;
  24. return impl::call(cons.cdr, cdr_type(cons.car, state));
  25. }
  26. };
  27. template<typename State>
  28. struct reverse_cons<nil_, State>
  29. {
  30. typedef State type;
  31. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  32. static State const &call(nil_ const &, State const &state = State())
  33. {
  34. return state;
  35. }
  36. };
  37. }}}
  38. #endif