value_at.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_VALUE_AT_05052005_0229)
  7. #define FUSION_VALUE_AT_05052005_0229
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/mpl/int.hpp>
  10. #include <boost/mpl/if.hpp>
  11. #include <boost/mpl/or.hpp>
  12. #include <boost/mpl/less.hpp>
  13. #include <boost/mpl/empty_base.hpp>
  14. #include <boost/fusion/sequence/intrinsic_fwd.hpp>
  15. #include <boost/fusion/support/tag_of.hpp>
  16. #include <boost/fusion/support/category_of.hpp>
  17. namespace boost { namespace fusion
  18. {
  19. // Special tags:
  20. struct sequence_facade_tag;
  21. struct boost_tuple_tag; // boost::tuples::tuple tag
  22. struct boost_array_tag; // boost::array tag
  23. struct mpl_sequence_tag; // mpl sequence tag
  24. struct std_pair_tag; // std::pair tag
  25. namespace extension
  26. {
  27. template <typename Tag>
  28. struct value_at_impl
  29. {
  30. template <typename Sequence, typename N>
  31. struct apply;
  32. };
  33. template <>
  34. struct value_at_impl<sequence_facade_tag>
  35. {
  36. template <typename Sequence, typename N>
  37. struct apply : Sequence::template value_at<Sequence, N> {};
  38. };
  39. template <>
  40. struct value_at_impl<boost_tuple_tag>;
  41. template <>
  42. struct value_at_impl<boost_array_tag>;
  43. template <>
  44. struct value_at_impl<mpl_sequence_tag>;
  45. template <>
  46. struct value_at_impl<std_pair_tag>;
  47. }
  48. namespace detail
  49. {
  50. template <typename Sequence, typename N, typename Tag>
  51. struct value_at_impl
  52. : mpl::if_<
  53. mpl::or_<
  54. mpl::less<N, typename extension::size_impl<Tag>::template apply<Sequence>::type>
  55. , traits::is_unbounded<Sequence>
  56. >
  57. , typename extension::value_at_impl<Tag>::template apply<Sequence, N>
  58. , mpl::empty_base
  59. >::type
  60. {};
  61. }
  62. namespace result_of
  63. {
  64. template <typename Sequence, typename N>
  65. struct value_at
  66. : detail::value_at_impl<Sequence, N, typename detail::tag_of<Sequence>::type>
  67. {};
  68. template <typename Sequence, int N>
  69. struct value_at_c
  70. : fusion::result_of::value_at<Sequence, mpl::int_<N> >
  71. {};
  72. }
  73. }}
  74. #endif