]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/beast/core/detail/empty_base_optimization.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / beast / test / beast / core / detail / empty_base_optimization.cpp
1 //
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9
10 // Test that header file is self-contained.
11 #include <boost/beast/core/detail/empty_base_optimization.hpp>
12
13 #include <boost/beast/unit_test/suite.hpp>
14
15 namespace boost {
16 namespace beast {
17 namespace detail {
18
19 class empty_base_optimization_test
20 : public beast::unit_test::suite
21 {
22 public:
23 template<class T>
24 class test1
25 : private empty_base_optimization<T>
26 {
27 using Base = empty_base_optimization<T>;
28 void* m_p;
29 public:
30 explicit test1 (T const& t)
31 : Base (t)
32 {}
33
34 T& member() {return Base::member();}
35 T const& member() const {return Base::member();}
36 };
37
38 template<class T>
39 class test2
40 {
41 void* m_p;
42 T m_t;
43 public:
44 explicit test2 (T const& t)
45 : m_t (t)
46 {}
47
48 T& member() {return m_t;}
49 T const& member() const {return m_t;}
50 };
51
52 struct Empty
53 {
54 operator bool() {return true;}
55 };
56
57 static
58 bool
59 test_one()
60 {
61 test1<int> t1(1);
62 test2<int> t2(2);
63 static_assert(sizeof(t1) == sizeof(t2), "don't optimize for int");
64 if(t1.member() != 1)
65 return false;
66 if(t2.member() != 2)
67 return false;
68 return true;
69 }
70
71 static
72 bool
73 test_two()
74 {
75 test1<Empty> t1((Empty()));
76 test2<Empty> t2((Empty()));
77 static_assert(sizeof(t1) < sizeof(t2), "do optimize for Empty");
78 if(t1.member() != true)
79 return false;
80 if(t2.member() != true)
81 return false;
82 return true;
83 }
84
85 void
86 run()
87 {
88 BEAST_EXPECT(test_one());
89 BEAST_EXPECT(test_two());
90 pass();
91 }
92 };
93
94 BEAST_DEFINE_TESTSUITE(beast,core,empty_base_optimization);
95
96 } // detail
97 } // beast
98 } // boost