at_impl.hpp 2.1 KB

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