ptr_list_of.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Boost.Assign library
  2. //
  3. // Copyright Thorsten Ottosen 2003-2004. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see http://www.boost.org/libs/assign/
  9. //
  10. #include <boost/detail/workaround.hpp>
  11. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  12. # pragma warn -8091 // suppress warning in Boost.Test
  13. # pragma warn -8057 // unused argument argc/argv in Boost.Test
  14. #endif
  15. #include <boost/assign/ptr_list_of.hpp>
  16. #include <boost/test/test_tools.hpp>
  17. #include <boost/ptr_container/ptr_container.hpp>
  18. struct Foo
  19. {
  20. int i;
  21. Foo() : i(0)
  22. { }
  23. Foo( int i ) : i(i)
  24. { }
  25. Foo( int i, int ) : i(i)
  26. { }
  27. Foo( const char*, int i, int ) : i(i)
  28. { }
  29. };
  30. inline bool operator<( Foo l, Foo r )
  31. {
  32. return l.i < r.i;
  33. }
  34. template< class PtrCont >
  35. void check_ptr_list_of_impl()
  36. {
  37. using namespace std;
  38. using namespace boost;
  39. using namespace boost::assign;
  40. PtrCont deq;
  41. deq = ptr_list_of<Foo>( 42 )()()( 3, 3 )( "foo", 2, 1 );
  42. BOOST_CHECK( deq.size() == 5 );
  43. }
  44. void check_ptr_list_of()
  45. {
  46. check_ptr_list_of_impl< boost::ptr_deque<Foo> >();
  47. check_ptr_list_of_impl< boost::ptr_list<Foo> >();
  48. check_ptr_list_of_impl< boost::ptr_vector<Foo> >();
  49. }
  50. #include <boost/test/unit_test.hpp>
  51. using boost::unit_test::test_suite;
  52. test_suite* init_unit_test_suite( int argc, char* argv[] )
  53. {
  54. test_suite* test = BOOST_TEST_SUITE( "List Test Suite" );
  55. test->add( BOOST_TEST_CASE( &check_ptr_list_of ) );
  56. return test;
  57. }