]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/test/test_8600.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / thread / test / test_8600.cpp
1 // Copyright (C) 2013 Vicente Botet
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <boost/assert.hpp>
7 #include <boost/static_assert.hpp>
8 #include <vector>
9 #include <utility>
10 #include <type_traits>
11 #if 1
12
13 struct B {
14 int v;
15 B(int i) : v(i) {}
16 };
17
18 struct D: B {
19 D(int i) : B(i) {}
20 };
21
22 void fb(B const&) {}
23 void fd(D const&) {}
24
25 BOOST_STATIC_ASSERT(sizeof(B)==sizeof(D));
26
27 template <class T, class Allocator=std::allocator<T> >
28 class new_vector;
29 template <class T, class Allocator>
30 class new_vector : public std::vector<T,Allocator>
31 {
32 typedef std::vector<T,Allocator> base_type;
33 public:
34 new_vector() : base_type() {}
35 new_vector(unsigned s) : base_type(s) {}
36 };
37
38 template <class Allocator >
39 class new_vector<bool, Allocator>
40 {
41 //std::vector<char,typename Allocator::template rebind<char>::other > v;
42 int i;
43 public:
44 };
45
46 template <class T, class A>
47 typename std::enable_if<!std::is_same<T, bool>::value,
48 new_vector<T,A>&
49 >::type
50 new_vector_cast(std::vector<T,A> & v) {
51 return reinterpret_cast<new_vector<T,A>&>(v);
52 }
53
54 BOOST_STATIC_ASSERT(sizeof(std::vector<int>)==sizeof(new_vector<int>));
55 BOOST_STATIC_ASSERT(sizeof(std::vector<bool>)!=sizeof(new_vector<bool>));
56
57 void fb(std::vector<int> const&) {}
58 void fd(new_vector<int> const&) {}
59
60 int main() {
61 {
62 std::vector<int> b(1);
63 b[0] = 1;
64 new_vector<int> d = new_vector_cast(b);
65 BOOST_ASSERT(b[0] == d[0]);
66 }
67 {
68 //std::vector<bool> b;
69 //new_vector<bool> d = new_vector_cast(b); // compile fail
70 }
71 {
72 std::vector<int> b(1);
73 b[0] = 1;
74 fd(new_vector_cast(b));
75 }
76 {
77 new_vector<int> d(1);
78 d[0] = 1;
79 std::vector<int> b = d;
80 BOOST_ASSERT(b[0] == d[0]);
81 }
82 {
83 //new_vector<bool> d;
84 //std::vector<bool> b = d; // compile fail
85 }
86 {
87 new_vector<int> d(1);
88 d[0] = 1;
89 fd(d);
90 }
91 return 0;
92 }
93
94
95 #else
96 int main() {
97 {
98 B b(1);
99 D d = reinterpret_cast<D&>(b);
100 BOOST_ASSERT(b.v == d.v);
101 }
102 {
103 B b(1);
104 fd(reinterpret_cast<D&>(b));
105 }
106 {
107 D d(2);
108 B b = d;
109 BOOST_ASSERT(b.v == d.v);
110 }
111 {
112 D d(2);
113 fd(d);
114 }
115 return 0;
116 }
117
118 #define BOOST_THREAD_VERSION 4
119
120 #include <iostream>
121 #include <boost/thread.hpp>
122
123 int calculate_the_answer_to_life_the_universe_and_everything()
124 {
125 return 42;
126 }
127
128 int main()
129 {
130 boost::packaged_task<int()> pt(calculate_the_answer_to_life_the_universe_and_everything);
131 boost::shared_future<int> fi1 = boost::shared_future<int>(pt.get_future());
132 boost::shared_future<int> fi2 = fi1;
133
134 boost::thread task(boost::move(pt)); // launch task on a thread
135
136 boost::wait_for_any(fi1, fi2);
137 std::cout << "Wait for any returned\n";
138 return (0);
139 }
140 #endif