at.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*=============================================================================
  2. Copyright (c) 2005-2008 Hartmut Kaiser
  3. Copyright (c) 2005-2007 Joel de Guzman
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #ifndef PHOENIX_SEQUENCE_AT_HPP
  8. #define PHOENIX_SEQUENCE_AT_HPP
  9. #include <boost/fusion/include/at.hpp>
  10. #include <boost/spirit/home/phoenix/core/actor.hpp>
  11. #include <boost/spirit/home/phoenix/core/compose.hpp>
  12. #include <boost/type_traits/remove_reference.hpp>
  13. namespace boost { namespace phoenix
  14. {
  15. template <int N>
  16. struct at_eval
  17. {
  18. template <typename Env, typename Tuple>
  19. struct result
  20. {
  21. typedef typename Tuple::template result<Env>::type tuple;
  22. typedef typename
  23. fusion::result_of::at_c<
  24. typename remove_reference<tuple>::type, N
  25. >::type
  26. type;
  27. };
  28. template <typename RT, typename Env, typename Tuple>
  29. static RT
  30. eval(Env const& env, Tuple const& t)
  31. {
  32. return fusion::at_c<N>(t.eval(env));
  33. }
  34. };
  35. template <int N, typename Tuple>
  36. inline actor<typename as_composite<at_eval<N>, Tuple>::type>
  37. at_c(Tuple const& tup)
  38. {
  39. return compose<at_eval<N> >(tup);
  40. }
  41. }}
  42. #endif