at_impl.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*=============================================================================
  2. Copyright (c) 2005-2012 Joel de Guzman
  3. Copyright (c) 2005-2006 Dan Marsden
  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. #if !defined(BOOST_FUSION_DEQUE_AT_IMPL_09122006_2017)
  8. #define BOOST_FUSION_DEQUE_AT_IMPL_09122006_2017
  9. #include <boost/fusion/support/config.hpp>
  10. #include <boost/fusion/container/deque/detail/keyed_element.hpp>
  11. #include <boost/mpl/eval_if.hpp>
  12. #include <boost/mpl/equal_to.hpp>
  13. #include <boost/mpl/assert.hpp>
  14. #include <boost/mpl/identity.hpp>
  15. #include <boost/type_traits/is_const.hpp>
  16. #include <boost/type_traits/add_const.hpp>
  17. #include <boost/type_traits/add_reference.hpp>
  18. namespace boost { namespace fusion
  19. {
  20. struct deque_tag;
  21. namespace extension
  22. {
  23. template<typename T>
  24. struct at_impl;
  25. template<>
  26. struct at_impl<deque_tag>
  27. {
  28. template<typename Sequence, typename N>
  29. struct apply
  30. {
  31. typedef typename Sequence::next_up next_up;
  32. typedef typename Sequence::next_down next_down;
  33. BOOST_MPL_ASSERT_RELATION(next_down::value, !=, next_up::value);
  34. static int const offset = next_down::value + 1;
  35. typedef mpl::int_<(N::value + offset)> adjusted_index;
  36. typedef typename
  37. detail::keyed_element_value_at<Sequence, adjusted_index>::type
  38. element_type;
  39. typedef typename
  40. add_reference<
  41. typename mpl::eval_if<
  42. is_const<Sequence>,
  43. add_const<element_type>,
  44. mpl::identity<element_type> >::type
  45. >::type
  46. type;
  47. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  48. static type call(Sequence& seq)
  49. {
  50. return seq.get(adjusted_index());
  51. }
  52. };
  53. };
  54. }
  55. }}
  56. #endif