begin.hpp 2.7 KB

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