• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // Copyright (C) 2011 Vicente J. Botet Escriba
10 //
11 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
12 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 
14 // <boost/thread/thread.hpp>
15 
16 // class thread
17 
18 // template <class F, class ...Args> thread(F&& f, Args&&... args);
19 
20 #define BOOST_THREAD_VERSION 4
21 
22 #include <boost/thread/thread_only.hpp>
23 #include <new>
24 #include <cstdlib>
25 #include <cassert>
26 #include <boost/detail/lightweight_test.hpp>
27 
28 class MoveOnly
29 {
30 public:
31   BOOST_THREAD_MOVABLE_ONLY(MoveOnly)
MoveOnly()32   MoveOnly()
33   {
34   }
MoveOnly(BOOST_THREAD_RV_REF (MoveOnly))35   MoveOnly(BOOST_THREAD_RV_REF(MoveOnly))
36   {}
37 
operator ()(BOOST_THREAD_RV_REF (MoveOnly))38   void operator()(BOOST_THREAD_RV_REF(MoveOnly))
39   {
40   }
41 };
42 
43 class M
44 {
45 
46 public:
47   long data_;
48   static int n_moves;
49 
BOOST_THREAD_MOVABLE_ONLY(M)50   BOOST_THREAD_MOVABLE_ONLY(M)
51   static void reset() {
52     n_moves=0;
53   }
M(long i)54   explicit M(long i) : data_(i)
55   {
56   }
M(BOOST_THREAD_RV_REF (M)a)57   M(BOOST_THREAD_RV_REF(M) a) : data_(BOOST_THREAD_RV(a).data_)
58   {
59     BOOST_THREAD_RV(a).data_ = -1;
60     ++n_moves;
61   }
operator =(BOOST_THREAD_RV_REF (M)a)62   M& operator=(BOOST_THREAD_RV_REF(M) a)
63   {
64     data_ = BOOST_THREAD_RV(a).data_;
65     BOOST_THREAD_RV(a).data_ = -1;
66     ++n_moves;
67     return *this;
68   }
~M()69   ~M()
70   {
71   }
72 
operator ()(int) const73   void operator()(int) const
74   { }
operator ()() const75   long operator()() const
76   { return data_;}
operator ()(long i,long j) const77   long operator()(long i, long j) const
78   { return data_ + i + j;}
79 };
80 
81 int M::n_moves = 0;
82 
fct(BOOST_THREAD_RV_REF (M)v)83 void fct(BOOST_THREAD_RV_REF(M) v)
84 {
85   BOOST_TEST_EQ(v.data_, 1);
86 }
87 
main()88 int main()
89 {
90 #if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
91   {
92     boost::thread t = boost::thread( MoveOnly(), MoveOnly() );
93     t.join();
94   }
95   {
96     M::reset();
97     boost::thread t = boost::thread( fct, M(1) );
98     t.join();
99     BOOST_TEST_EQ(M::n_moves, 2);
100   }
101 #endif
102   return boost::report_errors();
103 }
104