segments.hpp 2.3 KB

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