size.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_SIZE_05052005_0214)
  7. #define FUSION_SIZE_05052005_0214
  8. #include <boost/utility/enable_if.hpp>
  9. #include <boost/mpl/if.hpp>
  10. #include <boost/mpl/int.hpp>
  11. #include <boost/fusion/sequence/intrinsic_fwd.hpp>
  12. #include <boost/fusion/support/tag_of.hpp>
  13. #include <boost/fusion/support/is_segmented.hpp>
  14. #include <boost/fusion/sequence/intrinsic/detail/segmented_size.hpp>
  15. namespace boost { namespace fusion
  16. {
  17. // Special tags:
  18. struct sequence_facade_tag;
  19. struct boost_tuple_tag; // boost::tuples::tuple tag
  20. struct boost_array_tag; // boost::array tag
  21. struct mpl_sequence_tag; // mpl sequence tag
  22. struct std_pair_tag; // std::pair tag
  23. namespace extension
  24. {
  25. template <typename Tag>
  26. struct size_impl
  27. {
  28. template<typename Sequence>
  29. struct unsegmented_size : Sequence::size {};
  30. template <typename Sequence>
  31. struct apply
  32. : mpl::if_<
  33. traits::is_segmented<Sequence>
  34. , detail::segmented_size<Sequence>
  35. , unsegmented_size<Sequence>
  36. >::type
  37. {};
  38. };
  39. template <>
  40. struct size_impl<sequence_facade_tag>
  41. {
  42. template <typename Sequence>
  43. struct apply : Sequence::template size<Sequence> {};
  44. };
  45. template <>
  46. struct size_impl<boost_tuple_tag>;
  47. template <>
  48. struct size_impl<boost_array_tag>;
  49. template <>
  50. struct size_impl<mpl_sequence_tag>;
  51. template <>
  52. struct size_impl<std_pair_tag>;
  53. }
  54. namespace result_of
  55. {
  56. template <typename Sequence>
  57. struct size
  58. : extension::size_impl<typename detail::tag_of<Sequence>::type>::
  59. template apply<Sequence>
  60. {
  61. typedef typename extension::size_impl<typename detail::tag_of<Sequence>::type>::
  62. template apply<Sequence>::type size_application;
  63. BOOST_STATIC_CONSTANT(int, value = size_application::value);
  64. };
  65. }
  66. template <typename Sequence>
  67. inline typename result_of::size<Sequence>::type
  68. size(Sequence const&)
  69. {
  70. typedef typename result_of::size<Sequence>::type result;
  71. return result();
  72. }
  73. }}
  74. #endif