summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/thread/test/test_8600.cpp
blob: 224e41fa6a339f09e0d0a882f997a7bacd867725 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright (C) 2013 Vicente Botet
//
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/assert.hpp>
#include <boost/static_assert.hpp>
#include <vector>
#include <utility>
#include <type_traits>
#if 1

struct B {
  int v;
  B(int i) : v(i)  {}
};

struct D: B {
  D(int i) : B(i)  {}
};

void fb(B const&) {}
void fd(D const&) {}

BOOST_STATIC_ASSERT(sizeof(B)==sizeof(D));

template <class T, class Allocator=std::allocator<T> >
class new_vector;
template <class T, class Allocator>
class new_vector : public std::vector<T,Allocator>
{
  typedef std::vector<T,Allocator> base_type;
public:
  new_vector() : base_type()  {}
  new_vector(unsigned s) : base_type(s)  {}
};

template <class Allocator >
class new_vector<bool, Allocator>
{
  //std::vector<char,typename Allocator::template rebind<char>::other > v;
  int i;
public:
};

template <class T, class A>
typename std::enable_if<!std::is_same<T, bool>::value,
  new_vector<T,A>&
>::type
new_vector_cast(std::vector<T,A> & v) {
  return reinterpret_cast<new_vector<T,A>&>(v);
}

BOOST_STATIC_ASSERT(sizeof(std::vector<int>)==sizeof(new_vector<int>));
BOOST_STATIC_ASSERT(sizeof(std::vector<bool>)!=sizeof(new_vector<bool>));

void fb(std::vector<int> const&) {}
void fd(new_vector<int> const&) {}

int main() {
  {
    std::vector<int> b(1);
    b[0] = 1;
    new_vector<int> d = new_vector_cast(b);
    BOOST_ASSERT(b[0] == d[0]);
  }
  {
    //std::vector<bool> b;
    //new_vector<bool> d = new_vector_cast(b); // compile fail
  }
  {
    std::vector<int> b(1);
    b[0] = 1;
    fd(new_vector_cast(b));
  }
  {
    new_vector<int> d(1);
    d[0] = 1;
    std::vector<int> b = d;
    BOOST_ASSERT(b[0] == d[0]);
  }
  {
    //new_vector<bool> d;
    //std::vector<bool> b = d; // compile fail
  }
  {
    new_vector<int> d(1);
    d[0] = 1;
    fd(d);
  }
  return 0;
}


#else
int main() {
  {
    B b(1);
    D d = reinterpret_cast<D&>(b);
    BOOST_ASSERT(b.v == d.v);
  }
  {
    B b(1);
    fd(reinterpret_cast<D&>(b));
  }
  {
    D d(2);
    B b = d;
    BOOST_ASSERT(b.v == d.v);
  }
  {
    D d(2);
    fd(d);
  }
  return 0;
}

#define BOOST_THREAD_VERSION 4

#include <iostream>
#include <boost/thread.hpp>

int calculate_the_answer_to_life_the_universe_and_everything()
{
return 42;
}

int main()
{
boost::packaged_task<int()> pt(calculate_the_answer_to_life_the_universe_and_everything);
boost::shared_future<int> fi1 = boost::shared_future<int>(pt.get_future());
boost::shared_future<int> fi2 = fi1;

boost::thread task(boost::move(pt)); // launch task on a thread

boost::wait_for_any(fi1, fi2);
std::cout << "Wait for any returned\n";
return (0);
}
#endif