joint_view.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_JOINT_VIEW_07162005_0140)
  7. #define FUSION_JOINT_VIEW_07162005_0140
  8. #include <boost/fusion/view/joint_view/joint_view_fwd.hpp>
  9. #include <boost/fusion/support/detail/access.hpp>
  10. #include <boost/fusion/support/is_view.hpp>
  11. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  12. #include <boost/fusion/sequence/intrinsic/end.hpp>
  13. #include <boost/fusion/sequence/intrinsic/size.hpp>
  14. #include <boost/fusion/view/joint_view/joint_view_iterator.hpp>
  15. #include <boost/fusion/view/joint_view/detail/begin_impl.hpp>
  16. #include <boost/fusion/view/joint_view/detail/end_impl.hpp>
  17. #include <boost/fusion/support/sequence_base.hpp>
  18. #include <boost/mpl/if.hpp>
  19. #include <boost/mpl/plus.hpp>
  20. #include <boost/mpl/bool.hpp>
  21. #include <boost/mpl/eval_if.hpp>
  22. #include <boost/mpl/inherit.hpp>
  23. #include <boost/mpl/identity.hpp>
  24. namespace boost { namespace fusion
  25. {
  26. struct joint_view_tag;
  27. struct forward_traversal_tag;
  28. struct fusion_sequence_tag;
  29. template <typename Sequence1, typename Sequence2>
  30. struct joint_view : sequence_base<joint_view<Sequence1, Sequence2> >
  31. {
  32. typedef joint_view_tag fusion_tag;
  33. typedef fusion_sequence_tag tag; // this gets picked up by MPL
  34. typedef typename
  35. mpl::eval_if<
  36. mpl::and_<
  37. traits::is_associative<Sequence1>
  38. , traits::is_associative<Sequence2>
  39. >
  40. , mpl::inherit2<forward_traversal_tag,associative_tag>
  41. , mpl::identity<forward_traversal_tag>
  42. >::type
  43. category;
  44. typedef mpl::true_ is_view;
  45. typedef typename result_of::begin<Sequence1>::type first_type;
  46. typedef typename result_of::end<Sequence1>::type last_type;
  47. typedef typename result_of::begin<Sequence2>::type concat_type;
  48. typedef typename result_of::end<Sequence2>::type concat_last_type;
  49. typedef typename mpl::int_<
  50. result_of::size<Sequence1>::value + result_of::size<Sequence2>::value>
  51. size;
  52. joint_view(Sequence1& in_seq1, Sequence2& in_seq2)
  53. : seq1(in_seq1)
  54. , seq2(in_seq2)
  55. {}
  56. first_type first() const { return fusion::begin(seq1); }
  57. concat_type concat() const { return fusion::begin(seq2); }
  58. concat_last_type concat_last() const { return fusion::end(seq2); }
  59. private:
  60. // silence MSVC warning C4512: assignment operator could not be generated
  61. joint_view& operator= (joint_view const&);
  62. typename mpl::if_<traits::is_view<Sequence1>, Sequence1, Sequence1&>::type seq1;
  63. typename mpl::if_<traits::is_view<Sequence2>, Sequence2, Sequence2&>::type seq2;
  64. };
  65. }}
  66. #endif