size.hpp 2.5 KB

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