Chris@16
|
1 /*
|
Chris@16
|
2 * Copyright Andrey Semashev 2007 - 2013.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file light_function.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 20.06.2010
|
Chris@16
|
11 *
|
Chris@16
|
12 * \brief This header is the Boost.Log library impl, see the library documentation
|
Chris@16
|
13 * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
|
Chris@16
|
14 *
|
Chris@16
|
15 * The file contains a lightweight alternative of Boost.Function. It does not provide all
|
Chris@16
|
16 * features of Boost.Function but doesn't introduce dependency on Boost.Bind.
|
Chris@16
|
17 */
|
Chris@16
|
18
|
Chris@16
|
19 #ifndef BOOST_LOG_DETAIL_LIGHT_FUNCTION_HPP_INCLUDED_
|
Chris@16
|
20 #define BOOST_LOG_DETAIL_LIGHT_FUNCTION_HPP_INCLUDED_
|
Chris@16
|
21
|
Chris@16
|
22 #include <cstddef>
|
Chris@16
|
23 #include <boost/move/core.hpp>
|
Chris@16
|
24 #include <boost/move/utility.hpp>
|
Chris@16
|
25 #include <boost/log/detail/config.hpp>
|
Chris@16
|
26 #include <boost/utility/explicit_operator_bool.hpp>
|
Chris@16
|
27 #include <boost/type_traits/remove_cv.hpp>
|
Chris@16
|
28 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
29 #include <boost/preprocessor/iteration/iterate.hpp>
|
Chris@16
|
30 #include <boost/preprocessor/repetition/enum_params.hpp>
|
Chris@16
|
31 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
Chris@16
|
32 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
|
Chris@16
|
33 #include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
|
Chris@16
|
34 #endif
|
Chris@16
|
35 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
36 #include <boost/utility/enable_if.hpp>
|
Chris@16
|
37 #include <boost/type_traits/is_same.hpp>
|
Chris@16
|
38 #include <boost/mpl/or.hpp>
|
Chris@16
|
39 #else
|
Chris@16
|
40 #include <boost/type_traits/remove_reference.hpp>
|
Chris@16
|
41 #endif
|
Chris@16
|
42 #if defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
43 #include <boost/assert.hpp>
|
Chris@16
|
44 #endif
|
Chris@16
|
45 #include <boost/log/detail/header.hpp>
|
Chris@16
|
46
|
Chris@16
|
47 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
48 #pragma once
|
Chris@16
|
49 #endif
|
Chris@16
|
50
|
Chris@16
|
51 #ifndef BOOST_LOG_LIGHT_FUNCTION_LIMIT
|
Chris@16
|
52 #define BOOST_LOG_LIGHT_FUNCTION_LIMIT 2
|
Chris@16
|
53 #endif
|
Chris@16
|
54
|
Chris@16
|
55 namespace boost {
|
Chris@16
|
56
|
Chris@16
|
57 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
58
|
Chris@16
|
59 namespace aux {
|
Chris@16
|
60
|
Chris@16
|
61 template< typename SignatureT >
|
Chris@16
|
62 class light_function;
|
Chris@16
|
63
|
Chris@16
|
64 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
65
|
Chris@16
|
66 template< typename ResultT, typename... ArgsT >
|
Chris@16
|
67 class light_function< ResultT (ArgsT...) >
|
Chris@16
|
68 {
|
Chris@16
|
69 typedef light_function this_type;
|
Chris@16
|
70 BOOST_COPYABLE_AND_MOVABLE(this_type)
|
Chris@16
|
71
|
Chris@16
|
72 public:
|
Chris@16
|
73 typedef ResultT result_type;
|
Chris@16
|
74
|
Chris@16
|
75 private:
|
Chris@16
|
76 struct impl_base
|
Chris@16
|
77 {
|
Chris@16
|
78 typedef result_type (*invoke_type)(impl_base*, ArgsT...);
|
Chris@16
|
79 const invoke_type invoke;
|
Chris@16
|
80
|
Chris@16
|
81 typedef impl_base* (*clone_type)(const impl_base*);
|
Chris@16
|
82 const clone_type clone;
|
Chris@16
|
83
|
Chris@16
|
84 typedef void (*destroy_type)(impl_base*);
|
Chris@16
|
85 const destroy_type destroy;
|
Chris@16
|
86
|
Chris@16
|
87 impl_base(invoke_type inv, clone_type cl, destroy_type dstr) : invoke(inv), clone(cl), destroy(dstr)
|
Chris@16
|
88 {
|
Chris@16
|
89 }
|
Chris@16
|
90 };
|
Chris@16
|
91
|
Chris@16
|
92 #if !defined(BOOST_LOG_NO_MEMBER_TEMPLATE_FRIENDS)
|
Chris@16
|
93 template< typename FunT >
|
Chris@16
|
94 class impl;
|
Chris@16
|
95 template< typename FunT >
|
Chris@16
|
96 friend class impl;
|
Chris@16
|
97 #endif
|
Chris@16
|
98
|
Chris@16
|
99 template< typename FunT >
|
Chris@16
|
100 class impl :
|
Chris@16
|
101 public impl_base
|
Chris@16
|
102 {
|
Chris@16
|
103 typedef impl< FunT > this_type;
|
Chris@16
|
104
|
Chris@16
|
105 FunT m_Function;
|
Chris@16
|
106
|
Chris@16
|
107 public:
|
Chris@16
|
108 explicit impl(FunT const& fun) :
|
Chris@16
|
109 impl_base(&this_type::invoke_impl, &this_type::clone_impl, &this_type::destroy_impl),
|
Chris@16
|
110 m_Function(fun)
|
Chris@16
|
111 {
|
Chris@16
|
112 }
|
Chris@16
|
113
|
Chris@16
|
114 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
115 explicit impl(FunT&& fun) :
|
Chris@16
|
116 impl_base(&this_type::invoke_impl, &this_type::clone_impl, &this_type::destroy_impl),
|
Chris@16
|
117 m_Function(fun)
|
Chris@16
|
118 {
|
Chris@16
|
119 }
|
Chris@16
|
120 #endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
121
|
Chris@16
|
122 static void destroy_impl(impl_base* self)
|
Chris@16
|
123 {
|
Chris@16
|
124 delete static_cast< impl* >(self);
|
Chris@16
|
125 }
|
Chris@16
|
126 static impl_base* clone_impl(const impl_base* self)
|
Chris@16
|
127 {
|
Chris@16
|
128 return new impl(static_cast< const impl* >(self)->m_Function);
|
Chris@16
|
129 }
|
Chris@16
|
130 static result_type invoke_impl(impl_base* self, ArgsT... args)
|
Chris@16
|
131 {
|
Chris@16
|
132 return static_cast< impl* >(self)->m_Function(args...);
|
Chris@16
|
133 }
|
Chris@16
|
134 };
|
Chris@16
|
135
|
Chris@16
|
136 private:
|
Chris@16
|
137 impl_base* m_pImpl;
|
Chris@16
|
138
|
Chris@16
|
139 public:
|
Chris@16
|
140 BOOST_CONSTEXPR light_function() BOOST_NOEXCEPT : m_pImpl(NULL)
|
Chris@16
|
141 {
|
Chris@16
|
142 }
|
Chris@16
|
143 light_function(this_type const& that)
|
Chris@16
|
144 {
|
Chris@16
|
145 if (that.m_pImpl)
|
Chris@16
|
146 m_pImpl = that.m_pImpl->clone(that.m_pImpl);
|
Chris@16
|
147 else
|
Chris@16
|
148 m_pImpl = NULL;
|
Chris@16
|
149 }
|
Chris@16
|
150
|
Chris@16
|
151 light_function(BOOST_RV_REF(this_type) that) BOOST_NOEXCEPT
|
Chris@16
|
152 {
|
Chris@16
|
153 m_pImpl = that.m_pImpl;
|
Chris@16
|
154 that.m_pImpl = NULL;
|
Chris@16
|
155 }
|
Chris@16
|
156
|
Chris@16
|
157 light_function(BOOST_RV_REF(const this_type) that) BOOST_NOEXCEPT
|
Chris@16
|
158 {
|
Chris@16
|
159 m_pImpl = that.m_pImpl;
|
Chris@16
|
160 ((this_type&)that).m_pImpl = NULL;
|
Chris@16
|
161 }
|
Chris@16
|
162
|
Chris@16
|
163 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
164 template< typename FunT >
|
Chris@16
|
165 light_function(FunT&& fun) :
|
Chris@16
|
166 m_pImpl(new impl< typename remove_cv< typename remove_reference< FunT >::type >::type >(boost::forward< FunT >(fun)))
|
Chris@16
|
167 {
|
Chris@16
|
168 }
|
Chris@16
|
169 #else
|
Chris@16
|
170 template< typename FunT >
|
Chris@16
|
171 light_function(FunT const& fun, typename disable_if< mpl::or_< move_detail::is_rv< FunT >, is_same< FunT, this_type > >, int >::type = 0) :
|
Chris@16
|
172 m_pImpl(new impl< FunT >(fun))
|
Chris@16
|
173 {
|
Chris@16
|
174 }
|
Chris@16
|
175 template< typename FunT >
|
Chris@16
|
176 light_function(rv< FunT > const& fun, typename disable_if< is_same< typename remove_cv< FunT >::type, this_type >, int >::type = 0) :
|
Chris@16
|
177 m_pImpl(new impl< typename remove_cv< FunT >::type >(fun))
|
Chris@16
|
178 {
|
Chris@16
|
179 }
|
Chris@16
|
180 #endif
|
Chris@16
|
181
|
Chris@16
|
182 //! Constructor from NULL
|
Chris@16
|
183 #if !defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
184 BOOST_CONSTEXPR light_function(std::nullptr_t) BOOST_NOEXCEPT
|
Chris@16
|
185 #else
|
Chris@16
|
186 BOOST_CONSTEXPR light_function(int p) BOOST_NOEXCEPT
|
Chris@16
|
187 #endif
|
Chris@16
|
188 : m_pImpl(NULL)
|
Chris@16
|
189 {
|
Chris@16
|
190 #if defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
191 BOOST_ASSERT(p == 0);
|
Chris@16
|
192 #endif
|
Chris@16
|
193 }
|
Chris@16
|
194 ~light_function()
|
Chris@16
|
195 {
|
Chris@16
|
196 clear();
|
Chris@16
|
197 }
|
Chris@16
|
198
|
Chris@16
|
199 light_function& operator= (BOOST_RV_REF(this_type) that) BOOST_NOEXCEPT
|
Chris@16
|
200 {
|
Chris@16
|
201 this->swap(that);
|
Chris@16
|
202 return *this;
|
Chris@16
|
203 }
|
Chris@16
|
204 light_function& operator= (BOOST_COPY_ASSIGN_REF(this_type) that)
|
Chris@16
|
205 {
|
Chris@16
|
206 light_function tmp(that);
|
Chris@16
|
207 this->swap(tmp);
|
Chris@16
|
208 return *this;
|
Chris@16
|
209 }
|
Chris@16
|
210 //! Assignment of NULL
|
Chris@16
|
211 #if !defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
212 light_function& operator= (std::nullptr_t)
|
Chris@16
|
213 #else
|
Chris@16
|
214 light_function& operator= (int p)
|
Chris@16
|
215 #endif
|
Chris@16
|
216 {
|
Chris@16
|
217 #if defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
218 BOOST_ASSERT(p == 0);
|
Chris@16
|
219 #endif
|
Chris@16
|
220 clear();
|
Chris@16
|
221 return *this;
|
Chris@16
|
222 }
|
Chris@16
|
223 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
224 template< typename FunT >
|
Chris@16
|
225 light_function& operator= (FunT&& fun)
|
Chris@16
|
226 {
|
Chris@16
|
227 light_function tmp(boost::forward< FunT >(fun));
|
Chris@16
|
228 this->swap(tmp);
|
Chris@16
|
229 return *this;
|
Chris@16
|
230 }
|
Chris@16
|
231 #else
|
Chris@16
|
232 template< typename FunT >
|
Chris@16
|
233 typename disable_if< mpl::or_< move_detail::is_rv< FunT >, is_same< FunT, this_type > >, this_type& >::type
|
Chris@16
|
234 operator= (FunT const& fun)
|
Chris@16
|
235 {
|
Chris@16
|
236 light_function tmp(fun);
|
Chris@16
|
237 this->swap(tmp);
|
Chris@16
|
238 return *this;
|
Chris@16
|
239 }
|
Chris@16
|
240 #endif
|
Chris@16
|
241
|
Chris@16
|
242 result_type operator() (ArgsT... args) const
|
Chris@16
|
243 {
|
Chris@16
|
244 return m_pImpl->invoke(m_pImpl, args...);
|
Chris@16
|
245 }
|
Chris@16
|
246
|
Chris@16
|
247 BOOST_EXPLICIT_OPERATOR_BOOL()
|
Chris@16
|
248 bool operator! () const BOOST_NOEXCEPT { return (m_pImpl == NULL); }
|
Chris@16
|
249 bool empty() const BOOST_NOEXCEPT { return (m_pImpl == NULL); }
|
Chris@16
|
250 void clear() BOOST_NOEXCEPT
|
Chris@16
|
251 {
|
Chris@16
|
252 if (m_pImpl)
|
Chris@16
|
253 {
|
Chris@16
|
254 m_pImpl->destroy(m_pImpl);
|
Chris@16
|
255 m_pImpl = NULL;
|
Chris@16
|
256 }
|
Chris@16
|
257 }
|
Chris@16
|
258
|
Chris@16
|
259 void swap(this_type& that) BOOST_NOEXCEPT
|
Chris@16
|
260 {
|
Chris@16
|
261 register impl_base* p = m_pImpl;
|
Chris@16
|
262 m_pImpl = that.m_pImpl;
|
Chris@16
|
263 that.m_pImpl = p;
|
Chris@16
|
264 }
|
Chris@16
|
265 };
|
Chris@16
|
266
|
Chris@16
|
267 template< typename... ArgsT >
|
Chris@16
|
268 class light_function< void (ArgsT...) >
|
Chris@16
|
269 {
|
Chris@16
|
270 typedef light_function this_type;
|
Chris@16
|
271 BOOST_COPYABLE_AND_MOVABLE(this_type)
|
Chris@16
|
272
|
Chris@16
|
273 public:
|
Chris@16
|
274 typedef void result_type;
|
Chris@16
|
275
|
Chris@16
|
276 private:
|
Chris@16
|
277 struct impl_base
|
Chris@16
|
278 {
|
Chris@16
|
279 typedef void (*invoke_type)(impl_base*, ArgsT...);
|
Chris@16
|
280 const invoke_type invoke;
|
Chris@16
|
281
|
Chris@16
|
282 typedef impl_base* (*clone_type)(const impl_base*);
|
Chris@16
|
283 const clone_type clone;
|
Chris@16
|
284
|
Chris@16
|
285 typedef void (*destroy_type)(impl_base*);
|
Chris@16
|
286 const destroy_type destroy;
|
Chris@16
|
287
|
Chris@16
|
288 impl_base(invoke_type inv, clone_type cl, destroy_type dstr) : invoke(inv), clone(cl), destroy(dstr)
|
Chris@16
|
289 {
|
Chris@16
|
290 }
|
Chris@16
|
291 };
|
Chris@16
|
292
|
Chris@16
|
293 #if !defined(BOOST_LOG_NO_MEMBER_TEMPLATE_FRIENDS)
|
Chris@16
|
294 template< typename FunT >
|
Chris@16
|
295 class impl;
|
Chris@16
|
296 template< typename FunT >
|
Chris@16
|
297 friend class impl;
|
Chris@16
|
298 #endif
|
Chris@16
|
299
|
Chris@16
|
300 template< typename FunT >
|
Chris@16
|
301 class impl :
|
Chris@16
|
302 public impl_base
|
Chris@16
|
303 {
|
Chris@16
|
304 typedef impl< FunT > this_type;
|
Chris@16
|
305
|
Chris@16
|
306 FunT m_Function;
|
Chris@16
|
307
|
Chris@16
|
308 public:
|
Chris@16
|
309 explicit impl(FunT const& fun) :
|
Chris@16
|
310 impl_base(&this_type::invoke_impl, &this_type::clone_impl, &this_type::destroy_impl),
|
Chris@16
|
311 m_Function(fun)
|
Chris@16
|
312 {
|
Chris@16
|
313 }
|
Chris@16
|
314
|
Chris@16
|
315 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
316 explicit impl(FunT&& fun) :
|
Chris@16
|
317 impl_base(&this_type::invoke_impl, &this_type::clone_impl, &this_type::destroy_impl),
|
Chris@16
|
318 m_Function(fun)
|
Chris@16
|
319 {
|
Chris@16
|
320 }
|
Chris@16
|
321 #endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
322
|
Chris@16
|
323 static void destroy_impl(impl_base* self)
|
Chris@16
|
324 {
|
Chris@16
|
325 delete static_cast< impl* >(self);
|
Chris@16
|
326 }
|
Chris@16
|
327 static impl_base* clone_impl(const impl_base* self)
|
Chris@16
|
328 {
|
Chris@16
|
329 return new impl(static_cast< const impl* >(self)->m_Function);
|
Chris@16
|
330 }
|
Chris@16
|
331 static result_type invoke_impl(impl_base* self, ArgsT... args)
|
Chris@16
|
332 {
|
Chris@16
|
333 static_cast< impl* >(self)->m_Function(args...);
|
Chris@16
|
334 }
|
Chris@16
|
335 };
|
Chris@16
|
336
|
Chris@16
|
337 private:
|
Chris@16
|
338 impl_base* m_pImpl;
|
Chris@16
|
339
|
Chris@16
|
340 public:
|
Chris@16
|
341 BOOST_CONSTEXPR light_function() BOOST_NOEXCEPT : m_pImpl(NULL)
|
Chris@16
|
342 {
|
Chris@16
|
343 }
|
Chris@16
|
344 light_function(this_type const& that)
|
Chris@16
|
345 {
|
Chris@16
|
346 if (that.m_pImpl)
|
Chris@16
|
347 m_pImpl = that.m_pImpl->clone(that.m_pImpl);
|
Chris@16
|
348 else
|
Chris@16
|
349 m_pImpl = NULL;
|
Chris@16
|
350 }
|
Chris@16
|
351 light_function(BOOST_RV_REF(this_type) that) BOOST_NOEXCEPT
|
Chris@16
|
352 {
|
Chris@16
|
353 m_pImpl = that.m_pImpl;
|
Chris@16
|
354 that.m_pImpl = NULL;
|
Chris@16
|
355 }
|
Chris@16
|
356
|
Chris@16
|
357 light_function(BOOST_RV_REF(const this_type) that) BOOST_NOEXCEPT
|
Chris@16
|
358 {
|
Chris@16
|
359 m_pImpl = that.m_pImpl;
|
Chris@16
|
360 ((this_type&)that).m_pImpl = NULL;
|
Chris@16
|
361 }
|
Chris@16
|
362
|
Chris@16
|
363 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
364 template< typename FunT >
|
Chris@16
|
365 light_function(FunT&& fun) :
|
Chris@16
|
366 m_pImpl(new impl< typename remove_cv< typename remove_reference< FunT >::type >::type >(boost::forward< FunT >(fun)))
|
Chris@16
|
367 {
|
Chris@16
|
368 }
|
Chris@16
|
369 #else
|
Chris@16
|
370 template< typename FunT >
|
Chris@16
|
371 light_function(FunT const& fun, typename disable_if< mpl::or_< move_detail::is_rv< FunT >, is_same< FunT, this_type > >, int >::type = 0) :
|
Chris@16
|
372 m_pImpl(new impl< FunT >(fun))
|
Chris@16
|
373 {
|
Chris@16
|
374 }
|
Chris@16
|
375 template< typename FunT >
|
Chris@16
|
376 light_function(rv< FunT > const& fun, typename disable_if< is_same< typename remove_cv< FunT >::type, this_type >, int >::type = 0) :
|
Chris@16
|
377 m_pImpl(new impl< typename remove_cv< FunT >::type >(fun))
|
Chris@16
|
378 {
|
Chris@16
|
379 }
|
Chris@16
|
380 #endif
|
Chris@16
|
381
|
Chris@16
|
382 //! Constructor from NULL
|
Chris@16
|
383 #if !defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
384 BOOST_CONSTEXPR light_function(std::nullptr_t) BOOST_NOEXCEPT
|
Chris@16
|
385 #else
|
Chris@16
|
386 BOOST_CONSTEXPR light_function(int p) BOOST_NOEXCEPT
|
Chris@16
|
387 #endif
|
Chris@16
|
388 : m_pImpl(NULL)
|
Chris@16
|
389 {
|
Chris@16
|
390 #if defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
391 BOOST_ASSERT(p == 0);
|
Chris@16
|
392 #endif
|
Chris@16
|
393 }
|
Chris@16
|
394 ~light_function()
|
Chris@16
|
395 {
|
Chris@16
|
396 clear();
|
Chris@16
|
397 }
|
Chris@16
|
398
|
Chris@16
|
399 light_function& operator= (BOOST_RV_REF(this_type) that) BOOST_NOEXCEPT
|
Chris@16
|
400 {
|
Chris@16
|
401 this->swap(that);
|
Chris@16
|
402 return *this;
|
Chris@16
|
403 }
|
Chris@16
|
404 light_function& operator= (BOOST_COPY_ASSIGN_REF(this_type) that)
|
Chris@16
|
405 {
|
Chris@16
|
406 light_function tmp = that;
|
Chris@16
|
407 this->swap(tmp);
|
Chris@16
|
408 return *this;
|
Chris@16
|
409 }
|
Chris@16
|
410 //! Assignment of NULL
|
Chris@16
|
411 #if !defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
412 light_function& operator= (std::nullptr_t)
|
Chris@16
|
413 #else
|
Chris@16
|
414 light_function& operator= (int p)
|
Chris@16
|
415 #endif
|
Chris@16
|
416 {
|
Chris@16
|
417 #if defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
418 BOOST_ASSERT(p == 0);
|
Chris@16
|
419 #endif
|
Chris@16
|
420 clear();
|
Chris@16
|
421 return *this;
|
Chris@16
|
422 }
|
Chris@16
|
423 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
424 template< typename FunT >
|
Chris@16
|
425 light_function& operator= (FunT&& fun)
|
Chris@16
|
426 {
|
Chris@16
|
427 light_function tmp(boost::forward< FunT >(fun));
|
Chris@16
|
428 this->swap(tmp);
|
Chris@16
|
429 return *this;
|
Chris@16
|
430 }
|
Chris@16
|
431 #else
|
Chris@16
|
432 template< typename FunT >
|
Chris@16
|
433 typename disable_if< mpl::or_< move_detail::is_rv< FunT >, is_same< FunT, this_type > >, this_type& >::type
|
Chris@16
|
434 operator= (FunT const& fun)
|
Chris@16
|
435 {
|
Chris@16
|
436 light_function tmp(fun);
|
Chris@16
|
437 this->swap(tmp);
|
Chris@16
|
438 return *this;
|
Chris@16
|
439 }
|
Chris@16
|
440 #endif
|
Chris@16
|
441
|
Chris@16
|
442 result_type operator() (ArgsT... args) const
|
Chris@16
|
443 {
|
Chris@16
|
444 m_pImpl->invoke(m_pImpl, args...);
|
Chris@16
|
445 }
|
Chris@16
|
446
|
Chris@16
|
447 BOOST_EXPLICIT_OPERATOR_BOOL()
|
Chris@16
|
448 bool operator! () const BOOST_NOEXCEPT { return (m_pImpl == NULL); }
|
Chris@16
|
449 bool empty() const BOOST_NOEXCEPT { return (m_pImpl == NULL); }
|
Chris@16
|
450 void clear() BOOST_NOEXCEPT
|
Chris@16
|
451 {
|
Chris@16
|
452 if (m_pImpl)
|
Chris@16
|
453 {
|
Chris@16
|
454 m_pImpl->destroy(m_pImpl);
|
Chris@16
|
455 m_pImpl = NULL;
|
Chris@16
|
456 }
|
Chris@16
|
457 }
|
Chris@16
|
458
|
Chris@16
|
459 void swap(this_type& that) BOOST_NOEXCEPT
|
Chris@16
|
460 {
|
Chris@16
|
461 register impl_base* p = m_pImpl;
|
Chris@16
|
462 m_pImpl = that.m_pImpl;
|
Chris@16
|
463 that.m_pImpl = p;
|
Chris@16
|
464 }
|
Chris@16
|
465 };
|
Chris@16
|
466
|
Chris@16
|
467 #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
468
|
Chris@16
|
469 #define BOOST_PP_FILENAME_1 <boost/log/detail/light_function_pp.hpp>
|
Chris@16
|
470 #define BOOST_PP_ITERATION_LIMITS (0, BOOST_LOG_LIGHT_FUNCTION_LIMIT)
|
Chris@16
|
471 #include BOOST_PP_ITERATE()
|
Chris@16
|
472
|
Chris@16
|
473 #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
474
|
Chris@16
|
475 template< typename SignatureT >
|
Chris@16
|
476 inline void swap(light_function< SignatureT >& left, light_function< SignatureT >& right)
|
Chris@16
|
477 {
|
Chris@16
|
478 left.swap(right);
|
Chris@16
|
479 }
|
Chris@16
|
480
|
Chris@16
|
481 } // namespace aux
|
Chris@16
|
482
|
Chris@16
|
483 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
484
|
Chris@16
|
485 } // namespace boost
|
Chris@16
|
486
|
Chris@16
|
487 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
488
|
Chris@16
|
489 #endif // BOOST_LOG_DETAIL_LIGHT_FUNCTION_HPP_INCLUDED_
|