segmented_size.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*=============================================================================
  2. Copyright (c) 2011 Eric Niebler
  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(BOOST_FUSION_SEGMENTED_SIZE_08112006_1141)
  7. #define BOOST_FUSION_SEGMENTED_SIZE_08112006_1141
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/type_traits/add_const.hpp>
  10. #include <boost/type_traits/remove_reference.hpp>
  11. #include <boost/mpl/fold.hpp>
  12. #include <boost/mpl/plus.hpp>
  13. #include <boost/mpl/size_t.hpp>
  14. #include <boost/mpl/placeholders.hpp>
  15. #include <boost/fusion/sequence/intrinsic_fwd.hpp>
  16. #include <boost/fusion/mpl/begin.hpp>
  17. #include <boost/fusion/mpl/end.hpp>
  18. #include <boost/fusion/support/is_segmented.hpp>
  19. namespace boost { namespace fusion { namespace detail
  20. {
  21. ///////////////////////////////////////////////////////////////////////////
  22. // calculates the size of any segmented data structure.
  23. template<typename Sequence>
  24. struct segmented_size;
  25. ///////////////////////////////////////////////////////////////////////////
  26. template<typename Sequence, bool IsSegmented = traits::is_segmented<Sequence>::value>
  27. struct segmented_size_impl
  28. : mpl::fold<
  29. typename remove_reference<
  30. typename add_const<
  31. typename result_of::segments<Sequence>::type
  32. >::type
  33. >::type
  34. , mpl::size_t<0>
  35. , mpl::plus<mpl::_1, segmented_size<remove_reference<mpl::_2> > >
  36. >::type
  37. {};
  38. template<typename Sequence>
  39. struct segmented_size_impl<Sequence, false>
  40. : result_of::size<Sequence>::type
  41. {};
  42. template<typename Sequence>
  43. struct segmented_size
  44. : segmented_size_impl<Sequence>
  45. {};
  46. }}}
  47. #endif