1/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2// test_strong_typedef.cpp
3
4// (C) Copyright 2016 Ashish Sadanandan
5// Use, modification and distribution is subject to the Boost Software
6// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8
9// should pass compilation
10#include <stdlib.h> // EXIT_SUCCESS
11
12#include <boost/config.hpp>
13#include <boost/serialization/strong_typedef.hpp>
14#include <boost/static_assert.hpp>
15
16#include <boost/type_traits/has_nothrow_assign.hpp>
17#include <boost/type_traits/has_nothrow_constructor.hpp>
18#include <boost/type_traits/has_nothrow_copy.hpp>
19
20///////////////////////////////////////////////////////////////////////
21// Define a strong typedef for int.
22// The new type should be nothrow constructible and assignable.
23
24BOOST_STRONG_TYPEDEF(int, strong_int)
25
26#ifndef BOOST_HAS_NOTHROW_CONSTRUCTOR
27BOOST_STATIC_ASSERT(boost::has_nothrow_default_constructor<strong_int>::value);
28BOOST_STATIC_ASSERT(boost::has_nothrow_copy_constructor<strong_int>::value);
29BOOST_STATIC_ASSERT(boost::has_nothrow_assign<strong_int>::value);
30#endif
31
32///////////////////////////////////////////////////////////////////////
33// strong_int can now be placed in another type, which can also be
34// nothrow constructible and assignable.
35
36struct type1
37{
38 long some_long;
39 strong_int sint;
40};
41
42#ifndef BOOST_HAS_NOTHROW_CONSTRUCTOR
43BOOST_STATIC_ASSERT(boost::has_nothrow_default_constructor<type1>::value);
44BOOST_STATIC_ASSERT(boost::has_nothrow_copy_constructor<type1>::value);
45BOOST_STATIC_ASSERT(boost::has_nothrow_assign<type1>::value);
46#endif
47
48///////////////////////////////////////////////////////////////////////
49// Now define a type that throws, and a strong_typedef for it
50// The strong_typedef should also not have nothrow construction/assign.
51
52struct not_noexcept
53{
54 not_noexcept() {}
55 not_noexcept(not_noexcept const&) {}
56 not_noexcept& operator=(not_noexcept const&) {return *this;}
57 bool operator==(not_noexcept const&) const {return false;}
58 bool operator<(not_noexcept const&) const {return false;}
59};
60BOOST_STRONG_TYPEDEF(not_noexcept, strong_not_noexcept)
61
62#ifndef BOOST_HAS_NOTHROW_CONSTRUCTOR
63BOOST_STATIC_ASSERT(! boost::has_nothrow_default_constructor<strong_not_noexcept>::value);
64BOOST_STATIC_ASSERT(! boost::has_nothrow_copy_constructor<strong_not_noexcept>::value);
65BOOST_STATIC_ASSERT(! boost::has_nothrow_assign<strong_not_noexcept>::value);
66#endif
67
68int main()
69{
70 return EXIT_SUCCESS;
71}
72

source code of boost/libs/serialization/test/test_strong_typedef.cpp