insert_impl.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef BOOST_MPL_INSERT_IMPL_HPP_INCLUDED
  2. #define BOOST_MPL_INSERT_IMPL_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2000-2004
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/mpl for documentation.
  10. // $Id$
  11. // $Date$
  12. // $Revision$
  13. #include <boost/mpl/reverse_fold.hpp>
  14. #include <boost/mpl/iterator_range.hpp>
  15. #include <boost/mpl/clear.hpp>
  16. #include <boost/mpl/push_front.hpp>
  17. #include <boost/mpl/aux_/na_spec.hpp>
  18. #include <boost/mpl/aux_/traits_lambda_spec.hpp>
  19. #include <boost/type_traits/is_same.hpp>
  20. namespace boost { namespace mpl {
  21. // default implementation; conrete sequences might override it by
  22. // specializing either the 'insert_impl' or the primary 'insert' template
  23. template< typename Tag >
  24. struct insert_impl
  25. {
  26. template<
  27. typename Sequence
  28. , typename Pos
  29. , typename T
  30. >
  31. struct apply
  32. {
  33. typedef iterator_range<
  34. typename begin<Sequence>::type
  35. , Pos
  36. > first_half_;
  37. typedef iterator_range<
  38. Pos
  39. , typename end<Sequence>::type
  40. > second_half_;
  41. typedef typename reverse_fold<
  42. second_half_
  43. , typename clear<Sequence>::type
  44. , push_front<_,_>
  45. >::type half_sequence_;
  46. typedef typename reverse_fold<
  47. first_half_
  48. , typename push_front<half_sequence_,T>::type
  49. , push_front<_,_>
  50. >::type type;
  51. };
  52. };
  53. BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC(3,insert_impl)
  54. }}
  55. #endif // BOOST_MPL_INSERT_IMPL_HPP_INCLUDED