/Src/Dependencies/Boost/boost/fusion/algorithm/transformation/insert.hpp

http://hadesmem.googlecode.com/ · C++ Header · 63 lines · 50 code · 7 blank · 6 comment · 0 complexity · a076326a138e425666b7362482fa74c5 MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2006 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_07222005_0730)
  7. #define FUSION_INSERT_07222005_0730
  8. #include <boost/fusion/support/detail/as_fusion_element.hpp>
  9. #include <boost/fusion/iterator/mpl/convert_iterator.hpp>
  10. #include <boost/fusion/container/vector/vector10.hpp>
  11. #include <boost/fusion/view/joint_view/joint_view.hpp>
  12. #include <boost/fusion/view/single_view/single_view.hpp>
  13. #include <boost/fusion/view/iterator_range/iterator_range.hpp>
  14. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  15. #include <boost/fusion/sequence/intrinsic/end.hpp>
  16. #include <boost/fusion/adapted/mpl/mpl_iterator.hpp>
  17. namespace boost { namespace fusion
  18. {
  19. namespace result_of
  20. {
  21. template <typename Sequence, typename Position, typename T>
  22. struct insert
  23. {
  24. typedef typename detail::as_fusion_element<T>::type element_type;
  25. typedef typename convert_iterator<Position>::type pos_type;
  26. typedef typename result_of::begin<Sequence>::type first_type;
  27. typedef typename result_of::end<Sequence>::type last_type;
  28. typedef iterator_range<first_type, pos_type> left_type;
  29. typedef iterator_range<pos_type, last_type> right_type;
  30. typedef fusion::single_view<element_type> single_view;
  31. typedef joint_view<left_type, single_view const> left_insert_type;
  32. typedef joint_view<left_insert_type, right_type> type;
  33. };
  34. }
  35. template <typename Sequence, typename Position, typename T>
  36. inline typename result_of::insert<
  37. Sequence const, Position, T>::type
  38. insert(Sequence const& seq, Position const& pos, T const& x)
  39. {
  40. typedef result_of::insert<
  41. Sequence const, Position, T>
  42. result_of;
  43. typedef typename result_of::left_type left_type;
  44. typedef typename result_of::right_type right_type;
  45. typedef typename result_of::single_view single_view;
  46. typedef typename result_of::left_insert_type left_insert_type;
  47. typedef typename result_of::type result;
  48. left_type left(fusion::begin(seq), convert_iterator<Position>::call(pos));
  49. right_type right(convert_iterator<Position>::call(pos), fusion::end(seq));
  50. single_view insert(x);
  51. left_insert_type left_insert(left, insert);
  52. return result(left_insert, right);
  53. }
  54. }}
  55. #endif