joint_view.hpp 3.2 KB

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