1 // Copyright (C) 2013 Vicente Botet
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)
6 #include <boost/assert.hpp>
7 #include <boost/static_assert.hpp>
10 #include <type_traits>
25 BOOST_STATIC_ASSERT(sizeof(B
)==sizeof(D
));
27 template <class T
, class Allocator
=std::allocator
<T
> >
29 template <class T
, class Allocator
>
30 class new_vector
: public std::vector
<T
,Allocator
>
32 typedef std::vector
<T
,Allocator
> base_type
;
34 new_vector() : base_type() {}
35 new_vector(unsigned s
) : base_type(s
) {}
38 template <class Allocator
>
39 class new_vector
<bool, Allocator
>
41 //std::vector<char,typename Allocator::template rebind<char>::other > v;
46 template <class T
, class A
>
47 typename
std::enable_if
<!std::is_same
<T
, bool>::value
,
50 new_vector_cast(std::vector
<T
,A
> & v
) {
51 return reinterpret_cast<new_vector
<T
,A
>&>(v
);
54 BOOST_STATIC_ASSERT(sizeof(std::vector
<int>)==sizeof(new_vector
<int>));
55 BOOST_STATIC_ASSERT(sizeof(std::vector
<bool>)!=sizeof(new_vector
<bool>));
57 void fb(std::vector
<int> const&) {}
58 void fd(new_vector
<int> const&) {}
62 std::vector
<int> b(1);
64 new_vector
<int> d
= new_vector_cast(b
);
65 BOOST_ASSERT(b
[0] == d
[0]);
68 //std::vector<bool> b;
69 //new_vector<bool> d = new_vector_cast(b); // compile fail
72 std::vector
<int> b(1);
74 fd(new_vector_cast(b
));
79 std::vector
<int> b
= d
;
80 BOOST_ASSERT(b
[0] == d
[0]);
84 //std::vector<bool> b = d; // compile fail
99 D d
= reinterpret_cast<D
&>(b
);
100 BOOST_ASSERT(b
.v
== d
.v
);
104 fd(reinterpret_cast<D
&>(b
));
109 BOOST_ASSERT(b
.v
== d
.v
);
118 #define BOOST_THREAD_VERSION 4
121 #include <boost/thread.hpp>
123 int calculate_the_answer_to_life_the_universe_and_everything()
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
;
134 boost::thread
task(boost::move(pt
)); // launch task on a thread
136 boost::wait_for_any(fi1
, fi2
);
137 std::cout
<< "Wait for any returned\n";