std_typeinfo_ptr.cpp 920 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright (c) 2008 Joseph Gauterin, Niels Dekker
  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. // Tests swapping std::type_info pointers by means of boost::swap.
  7. // There is no std::swap overload or template specialization
  8. // for std::type_info pointers.
  9. #include <boost/utility/swap.hpp>
  10. #include <boost/core/lightweight_test.hpp>
  11. #define BOOST_CHECK BOOST_TEST
  12. #define BOOST_CHECK_EQUAL BOOST_TEST_EQ
  13. #include <typeinfo>
  14. int main()
  15. {
  16. const std::type_info * const initial_value1 = 0;
  17. const std::type_info * const initial_value2 = &typeid(double);
  18. const std::type_info * ptr1 = initial_value1;
  19. const std::type_info * ptr2 = initial_value2;
  20. boost::swap(ptr1,ptr2);
  21. BOOST_CHECK_EQUAL(ptr1,initial_value2);
  22. BOOST_CHECK_EQUAL(ptr2,initial_value1);
  23. return boost::report_errors();
  24. }