insert_range.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_INSERT_RANGE_009172005_1147)
  7. #define FUSION_INSERT_RANGE_009172005_1147
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/iterator/mpl/convert_iterator.hpp>
  10. #include <boost/fusion/view/joint_view/joint_view.hpp>
  11. #include <boost/fusion/view/iterator_range/iterator_range.hpp>
  12. #include <boost/fusion/support/detail/as_fusion_element.hpp>
  13. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  14. #include <boost/fusion/sequence/intrinsic/end.hpp>
  15. #include <boost/fusion/adapted/mpl/mpl_iterator.hpp>
  16. namespace boost { namespace fusion
  17. {
  18. namespace result_of
  19. {
  20. template <typename Sequence, typename Position, typename Range>
  21. struct insert_range
  22. {
  23. typedef typename convert_iterator<Position>::type pos_type;
  24. typedef typename result_of::begin<Sequence>::type first_type;
  25. typedef typename result_of::end<Sequence>::type last_type;
  26. typedef iterator_range<first_type, pos_type> left_type;
  27. typedef iterator_range<pos_type, last_type> right_type;
  28. typedef joint_view<left_type, Range> left_insert_type;
  29. typedef joint_view<left_insert_type, right_type> type;
  30. };
  31. }
  32. template <typename Sequence, typename Position, typename Range>
  33. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  34. inline typename result_of::insert_range<Sequence const, Position, Range const>::type
  35. insert_range(Sequence const& seq, Position const& pos, Range const& range)
  36. {
  37. typedef result_of::insert_range<Sequence const, Position, Range const> result_of;
  38. typedef typename result_of::left_type left_type;
  39. typedef typename result_of::right_type right_type;
  40. typedef typename result_of::left_insert_type left_insert_type;
  41. typedef typename result_of::type result;
  42. left_type left(fusion::begin(seq), convert_iterator<Position>::call(pos));
  43. right_type right(convert_iterator<Position>::call(pos), fusion::end(seq));
  44. left_insert_type left_insert(left, range);
  45. return result(left_insert, right);
  46. }
  47. }}
  48. #endif