1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Copyright (C) 2014 Vicente J. Botet Escriba
12 // Distributed under the Boost Software License, Version 1.0. (See accompanying
13 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
15 // <boost/thread/detail/invoke.hpp>
17 #include <boost/thread/detail/invoke.hpp>
18 #include <boost/detail/lightweight_test.hpp>
31 void operator()(int i)
36 void mem1() {++count;}
37 void mem2() const {count += 2;}
43 int save_count = count;
46 boost::detail::invoke(f_void_1, 2);
47 BOOST_TEST(count == save_count + 2);
52 void (*fp)(int) = f_void_1;
53 boost::detail::invoke(fp, 3);
54 BOOST_TEST(count == save_count+3);
60 #if defined BOOST_THREAD_PROVIDES_INVOKE
61 boost::detail::invoke(a0, 4);
62 BOOST_TEST(count == save_count+4);
65 boost::detail::invoke<void>(a0, 4);
66 BOOST_TEST(count == save_count+4);
69 // member function pointer
71 #if defined BOOST_THREAD_PROVIDES_INVOKE
72 void (A_void_1::*fp)() = &A_void_1::mem1;
73 boost::detail::invoke(fp, A_void_1());
74 BOOST_TEST(count == save_count+1);
77 boost::detail::invoke<void>(fp, A_void_1());
78 BOOST_TEST(count == save_count+1);
82 #if defined BOOST_THREAD_PROVIDES_INVOKE
84 boost::detail::invoke(fp, &a);
85 BOOST_TEST(count == save_count+1);
88 boost::detail::invoke<int>(fp, &a);
89 BOOST_TEST(count == save_count+1);
94 // const member function pointer
96 void (A_void_1::*fp)() const = &A_void_1::mem2;
97 boost::detail::invoke(fp, A_void_1());
98 BOOST_TEST(count == save_count+2);
101 boost::detail::invoke(fp, &a);
102 BOOST_TEST(count == save_count+2);
116 A_int_1() : data_(5) {}
117 int operator()(int i)
122 int mem1() {return 3;}
123 int mem2() const {return 4;}
132 BOOST_TEST(boost::detail::invoke(f_int_1, 2) == 3);
136 int (*fp)(int) = f_int_1;
137 BOOST_TEST(boost::detail::invoke(fp, 3) == 4);
141 #if defined BOOST_THREAD_PROVIDES_INVOKE
142 BOOST_TEST(boost::detail::invoke(A_int_1(), 4) == 3);
143 BOOST_TEST(boost::detail::invoke<int>(A_int_1(), 4) == 3);
146 // member function pointer
148 #if defined BOOST_THREAD_PROVIDES_INVOKE
149 BOOST_TEST(boost::detail::invoke(&A_int_1::mem1, A_int_1()) == 3);
150 BOOST_TEST(boost::detail::invoke<int>(&A_int_1::mem1, A_int_1()) == 3);
154 BOOST_TEST(boost::detail::invoke(&A_int_1::mem1, &a) == 3);
156 // const member function pointer
158 BOOST_TEST(boost::detail::invoke(&A_int_1::mem2, A_int_1()) == 4);
160 BOOST_TEST(boost::detail::invoke(&A_int_1::mem2, &a) == 4);
162 // member data pointer
164 #if defined BOOST_THREAD_PROVIDES_INVOKE
165 BOOST_TEST(boost::detail::invoke(&A_int_1::data_, A_int_1()) == 5);
166 BOOST_TEST(boost::detail::invoke<int>(&A_int_1::data_, A_int_1()) == 5);
168 BOOST_TEST(boost::detail::invoke(&A_int_1::data_, a) == 5);
169 boost::detail::invoke(&A_int_1::data_, a) = 6;
170 BOOST_TEST(boost::detail::invoke(&A_int_1::data_, a) == 6);
171 BOOST_TEST(boost::detail::invoke(&A_int_1::data_, &a) == 6);
172 boost::detail::invoke(&A_int_1::data_, &a) = 7;
173 BOOST_TEST(boost::detail::invoke(&A_int_1::data_, &a) == 7);
178 // 2 arg, return void
180 void f_void_2(int i, int j)
187 void operator()(int i, int j)
192 void mem1(int i) {count += i;}
193 void mem2(int i) const {count += i;}
199 int save_count = count;
202 boost::detail::invoke(f_void_2, 2, 3);
203 BOOST_TEST(count == save_count+5);
206 // member function pointer
208 #if defined BOOST_THREAD_PROVIDES_INVOKE
209 boost::detail::invoke(&A_void_2::mem1, A_void_2(), 3);
210 BOOST_TEST(count == save_count+3);
213 boost::detail::invoke<void>(&A_void_2::mem1, A_void_2(), 3);
214 BOOST_TEST(count == save_count+3);
226 return boost::report_errors();