begin.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_BEGIN_04052005_1132)
  7. #define FUSION_BEGIN_04052005_1132
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/utility/enable_if.hpp>
  10. #include <boost/mpl/empty_base.hpp>
  11. #include <boost/mpl/if.hpp>
  12. #include <boost/fusion/sequence/intrinsic_fwd.hpp>
  13. #include <boost/fusion/support/tag_of.hpp>
  14. #include <boost/fusion/support/is_sequence.hpp>
  15. #include <boost/fusion/support/is_segmented.hpp>
  16. #include <boost/fusion/sequence/intrinsic/detail/segmented_begin.hpp>
  17. namespace boost { namespace fusion
  18. {
  19. // Special tags:
  20. struct sequence_facade_tag; // iterator facade tag
  21. struct boost_tuple_tag; // boost::tuples::tuple tag
  22. struct boost_array_tag; // boost::array tag
  23. struct mpl_sequence_tag; // mpl sequence tag
  24. struct std_pair_tag; // std::pair tag
  25. namespace extension
  26. {
  27. template <typename Tag>
  28. struct begin_impl
  29. {
  30. template <typename Sequence>
  31. struct apply
  32. : mpl::if_<
  33. traits::is_segmented<Sequence>
  34. , detail::segmented_begin<Sequence>
  35. , mpl::empty_base
  36. >::type
  37. {};
  38. };
  39. template <>
  40. struct begin_impl<sequence_facade_tag>
  41. {
  42. template <typename Sequence>
  43. struct apply : Sequence::template begin<Sequence> {};
  44. };
  45. template <>
  46. struct begin_impl<boost_tuple_tag>;
  47. template <>
  48. struct begin_impl<boost_array_tag>;
  49. template <>
  50. struct begin_impl<mpl_sequence_tag>;
  51. template <>
  52. struct begin_impl<std_pair_tag>;
  53. }
  54. namespace result_of
  55. {
  56. template <typename Sequence>
  57. struct begin
  58. : extension::begin_impl<typename detail::tag_of<Sequence>::type>::
  59. template apply<Sequence>
  60. {};
  61. }
  62. template <typename Sequence>
  63. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  64. inline typename
  65. lazy_enable_if<
  66. traits::is_sequence<Sequence>
  67. , result_of::begin<Sequence>
  68. >::type const
  69. begin(Sequence& seq)
  70. {
  71. return result_of::begin<Sequence>::call(seq);
  72. }
  73. template <typename Sequence>
  74. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  75. inline typename
  76. lazy_enable_if<
  77. traits::is_sequence<Sequence>
  78. , result_of::begin<Sequence const>
  79. >::type const
  80. begin(Sequence const& seq)
  81. {
  82. return result_of::begin<Sequence const>::call(seq);
  83. }
  84. }}
  85. #endif