at.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  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(FUSION_AT_05042005_0722)
  7. #define FUSION_AT_05042005_0722
  8. #include <boost/mpl/int.hpp>
  9. #include <boost/type_traits/is_const.hpp>
  10. #include <boost/fusion/sequence/intrinsic_fwd.hpp>
  11. #include <boost/fusion/support/tag_of.hpp>
  12. #include <boost/fusion/support/detail/access.hpp>
  13. namespace boost { namespace fusion
  14. {
  15. // Special tags:
  16. struct sequence_facade_tag;
  17. struct boost_tuple_tag; // boost::tuples::tuple tag
  18. struct boost_array_tag; // boost::array tag
  19. struct mpl_sequence_tag; // mpl sequence tag
  20. struct std_pair_tag; // std::pair tag
  21. struct std_tuple_tag; // std::tuple tag
  22. namespace extension
  23. {
  24. template <typename Tag>
  25. struct at_impl
  26. {
  27. template <typename Sequence, typename N>
  28. struct apply;
  29. };
  30. template <>
  31. struct at_impl<sequence_facade_tag>
  32. {
  33. template <typename Sequence, typename N>
  34. struct apply : Sequence::template at<Sequence, N> {};
  35. };
  36. template <>
  37. struct at_impl<boost_tuple_tag>;
  38. template <>
  39. struct at_impl<boost_array_tag>;
  40. template <>
  41. struct at_impl<mpl_sequence_tag>;
  42. template <>
  43. struct at_impl<std_pair_tag>;
  44. template <>
  45. struct at_impl<std_tuple_tag>;
  46. }
  47. namespace result_of
  48. {
  49. template <typename Sequence, typename N>
  50. struct at
  51. : extension::at_impl<typename detail::tag_of<Sequence>::type>::
  52. template apply<Sequence, N>
  53. {};
  54. template <typename Sequence, int N>
  55. struct at_c
  56. : at<Sequence, mpl::int_<N> >
  57. {};
  58. }
  59. template <typename N, typename Sequence>
  60. inline typename
  61. lazy_disable_if<
  62. is_const<Sequence>
  63. , result_of::at<Sequence, N>
  64. >::type
  65. at(Sequence& seq)
  66. {
  67. return result_of::at<Sequence, N>::call(seq);
  68. }
  69. template <typename N, typename Sequence>
  70. inline typename result_of::at<Sequence const, N>::type
  71. at(Sequence const& seq)
  72. {
  73. return result_of::at<Sequence const, N>::call(seq);
  74. }
  75. template <int N, typename Sequence>
  76. inline typename
  77. lazy_disable_if<
  78. is_const<Sequence>
  79. , result_of::at_c<Sequence, N>
  80. >::type
  81. at_c(Sequence& seq)
  82. {
  83. return fusion::at<mpl::int_<N> >(seq);
  84. }
  85. template <int N, typename Sequence>
  86. inline typename result_of::at_c<Sequence const, N>::type
  87. at_c(Sequence const& seq)
  88. {
  89. return fusion::at<mpl::int_<N> >(seq);
  90. }
  91. }}
  92. #endif