segments.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*=============================================================================
  2. Copyright (c) 2006 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_SEGMENTS_04052005_1141)
  7. #define BOOST_FUSION_SEGMENTS_04052005_1141
  8. #include <boost/type_traits/is_const.hpp>
  9. #include <boost/utility/enable_if.hpp>
  10. #include <boost/fusion/sequence/intrinsic_fwd.hpp>
  11. #include <boost/fusion/support/tag_of.hpp>
  12. namespace boost { namespace fusion
  13. {
  14. // Special tags:
  15. struct sequence_facade_tag;
  16. struct iterator_range_tag;
  17. // segments: returns a sequence of sequences
  18. namespace extension
  19. {
  20. template <typename Tag>
  21. struct segments_impl
  22. {
  23. template <typename Sequence>
  24. struct apply {};
  25. };
  26. template <>
  27. struct segments_impl<sequence_facade_tag>
  28. {
  29. template <typename Sequence>
  30. struct apply : Sequence::template segments<Sequence> {};
  31. };
  32. template <>
  33. struct segments_impl<iterator_range_tag>;
  34. }
  35. namespace result_of
  36. {
  37. template <typename Sequence>
  38. struct segments
  39. {
  40. typedef typename traits::tag_of<Sequence>::type tag_type;
  41. typedef typename
  42. extension::segments_impl<tag_type>::template apply<Sequence>::type
  43. type;
  44. };
  45. }
  46. template <typename Sequence>
  47. inline typename
  48. lazy_disable_if<
  49. is_const<Sequence>
  50. , result_of::segments<Sequence>
  51. >::type
  52. segments(Sequence& seq)
  53. {
  54. typedef typename traits::tag_of<Sequence>::type tag_type;
  55. return extension::segments_impl<tag_type>::template apply<Sequence>::call(seq);
  56. }
  57. template <typename Sequence>
  58. inline typename result_of::segments<Sequence const>::type
  59. segments(Sequence const& seq)
  60. {
  61. typedef typename traits::tag_of<Sequence const>::type tag_type;
  62. return extension::segments_impl<tag_type>::template apply<Sequence const>::call(seq);
  63. }
  64. }}
  65. #endif