insert_range.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright Aleksey Gurtovoy 2001-2004
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/mpl for documentation.
  8. // $Id$
  9. // $Date$
  10. // $Revision$
  11. #include <boost/mpl/insert_range.hpp>
  12. #include <boost/mpl/find.hpp>
  13. #include <boost/mpl/vector_c.hpp>
  14. #include <boost/mpl/list.hpp>
  15. #include <boost/mpl/set.hpp>
  16. #include <boost/mpl/set_c.hpp>
  17. #include <boost/mpl/map.hpp>
  18. #include <boost/mpl/size.hpp>
  19. #include <boost/mpl/range_c.hpp>
  20. #include <boost/mpl/equal.hpp>
  21. #include <boost/mpl/fold.hpp>
  22. #include <boost/mpl/placeholders.hpp>
  23. #include <boost/mpl/logical.hpp>
  24. #include <boost/mpl/contains.hpp>
  25. #include <boost/mpl/joint_view.hpp>
  26. #include <boost/mpl/aux_/test.hpp>
  27. MPL_TEST_CASE()
  28. {
  29. typedef vector_c<int,0,1,7,8,9> numbers;
  30. typedef find< numbers,integral_c<int,7> >::type pos;
  31. typedef insert_range< numbers,pos,range_c<int,2,7> >::type range;
  32. MPL_ASSERT_RELATION( size<range>::value, ==, 10 );
  33. MPL_ASSERT(( equal< range,range_c<int,0,10> > ));
  34. typedef insert_range< list0<>,end< list0<> >::type,list1<int> >::type result2;
  35. MPL_ASSERT_RELATION( size<result2>::value, ==, 1 );
  36. }
  37. template<typename A, typename B>
  38. void test_associative()
  39. {
  40. typedef typename insert_range< A,typename end< A >::type,B >::type C;
  41. MPL_ASSERT_RELATION( size<C>::value, <=, (size<A>::value + size<B>::value) );
  42. MPL_ASSERT(( fold< joint_view< A,B >,true_,and_< _1,contains< C,_2 > > > ));
  43. }
  44. MPL_TEST_CASE()
  45. {
  46. typedef set3< short,int,long > signed_integers;
  47. typedef set3< unsigned short,unsigned int,unsigned long > unsigned_integers;
  48. test_associative<signed_integers, unsigned_integers>();
  49. typedef set_c< int,1,3,5,7,9 > odds;
  50. typedef set_c< int,0,2,4,6,8 > evens;
  51. test_associative<odds, evens>();
  52. typedef map2<
  53. pair< void,void* >
  54. , pair< int,int* >
  55. > pointers;
  56. typedef map2<
  57. pair< void const,void const* >
  58. , pair< int const,int const* >
  59. > pointers_to_const;
  60. test_associative<pointers, pointers_to_const>();
  61. }