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
13struct B {
14 int v;
15 B(int i) : v(i) {}
16};
17
18struct D: B {
19 D(int i) : B(i) {}
20};
21
22void fb(B const&) {}
23void fd(D const&) {}
24
25BOOST_STATIC_ASSERT(sizeof(B)==sizeof(D));
26
27template <class T, class Allocator=std::allocator<T> >
28class new_vector;
29template <class T, class Allocator>
30class new_vector : public std::vector<T,Allocator>
31{
32 typedef std::vector<T,Allocator> base_type;
33public:
34 new_vector() : base_type() {}
35 new_vector(unsigned s) : base_type(s) {}
36};
37
38template <class Allocator >
39class new_vector<bool, Allocator>
40{
41 //std::vector<char,typename Allocator::template rebind<char>::other > v;
42 int i;
43public:
44};
45
46template <class T, class A>
47typename std::enable_if<!std::is_same<T, bool>::value,
48 new_vector<T,A>&
49>::type
50new_vector_cast(std::vector<T,A> & v) {
51 return reinterpret_cast<new_vector<T,A>&>(v);
52}
53
54BOOST_STATIC_ASSERT(sizeof(std::vector<int>)==sizeof(new_vector<int>));
55BOOST_STATIC_ASSERT(sizeof(std::vector<bool>)!=sizeof(new_vector<bool>));
56
57void fb(std::vector<int> const&) {}
58void fd(new_vector<int> const&) {}
59
60int main() {
61 {
62 std::vector<int> b(1);
63 b[0] = 1;
64 new_vector<int> d = new_vector_cast(v&: 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(v&: 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
96int 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
123int calculate_the_answer_to_life_the_universe_and_everything()
124{
125return 42;
126}
127
128int main()
129{
130boost::packaged_task<int()> pt(calculate_the_answer_to_life_the_universe_and_everything);
131boost::shared_future<int> fi1 = boost::shared_future<int>(pt.get_future());
132boost::shared_future<int> fi2 = fi1;
133
134boost::thread task(boost::move(pt)); // launch task on a thread
135
136boost::wait_for_any(fi1, fi2);
137std::cout << "Wait for any returned\n";
138return (0);
139}
140#endif
141

source code of boost/libs/thread/test/test_8600.cpp