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