auto.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright (C) 2008-2018 Lorenzo Caminiti
  2. // Distributed under the Boost Software License, Version 1.0 (see accompanying
  3. // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
  4. // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
  5. // Test that OLD macro allows to use C++11 auto declarations.
  6. #include <boost/config.hpp>
  7. #include <boost/contract/old.hpp>
  8. #include <boost/type_traits.hpp>
  9. #include <boost/static_assert.hpp>
  10. #include <boost/detail/lightweight_test.hpp>
  11. int main() {
  12. int x = -123;
  13. auto old_x = BOOST_CONTRACT_OLDOF(x);
  14. x = 123;
  15. BOOST_STATIC_ASSERT((boost::is_same<decltype(old_x),
  16. boost::contract::old_ptr<int> >::value));
  17. #ifndef BOOST_CONTRACT_NO_OLDS
  18. BOOST_TEST_EQ(*old_x, -123);
  19. #endif
  20. BOOST_TEST_EQ(x, 123);
  21. boost::contract::virtual_* v = 0;
  22. char y = 'j';
  23. auto old_y = BOOST_CONTRACT_OLDOF(v, y);
  24. y = 'k';
  25. BOOST_STATIC_ASSERT((boost::is_same<decltype(old_y),
  26. boost::contract::old_ptr<char> >::value));
  27. #ifndef BOOST_CONTRACT_NO_OLDS
  28. BOOST_TEST_EQ(*old_y, 'j');
  29. #endif
  30. BOOST_TEST_EQ(y, 'k');
  31. return boost::report_errors();
  32. }