Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
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 #else
|
Chris@16
|
38 #include <boost/type_traits/remove_reference.hpp>
|
Chris@16
|
39 #endif
|
Chris@16
|
40 #if defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
41 #include <boost/assert.hpp>
|
Chris@16
|
42 #endif
|
Chris@16
|
43 #include <boost/log/detail/header.hpp>
|
Chris@16
|
44
|
Chris@16
|
45 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
46 #pragma once
|
Chris@16
|
47 #endif
|
Chris@16
|
48
|
Chris@16
|
49 #ifndef BOOST_LOG_LIGHT_FUNCTION_LIMIT
|
Chris@16
|
50 #define BOOST_LOG_LIGHT_FUNCTION_LIMIT 2
|
Chris@16
|
51 #endif
|
Chris@16
|
52
|
Chris@16
|
53 namespace boost {
|
Chris@16
|
54
|
Chris@16
|
55 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
56
|
Chris@16
|
57 namespace aux {
|
Chris@16
|
58
|
Chris@101
|
59 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@101
|
60
|
Chris@101
|
61 template< typename T, typename ThisT >
|
Chris@101
|
62 struct is_cv_same { enum _ { value = false }; };
|
Chris@101
|
63 template< typename T >
|
Chris@101
|
64 struct is_cv_same< T, T > { enum _ { value = true }; };
|
Chris@101
|
65 template< typename T >
|
Chris@101
|
66 struct is_cv_same< T, const T > { enum _ { value = true }; };
|
Chris@101
|
67 template< typename T >
|
Chris@101
|
68 struct is_cv_same< T, volatile T > { enum _ { value = true }; };
|
Chris@101
|
69 template< typename T >
|
Chris@101
|
70 struct is_cv_same< T, const volatile T > { enum _ { value = true }; };
|
Chris@101
|
71
|
Chris@101
|
72 template< typename T, typename ThisT >
|
Chris@101
|
73 struct is_rv_or_same { enum _ { value = false }; };
|
Chris@101
|
74 template< typename T >
|
Chris@101
|
75 struct is_rv_or_same< T, T > { enum _ { value = true }; };
|
Chris@101
|
76 template< typename T, typename ThisT >
|
Chris@101
|
77 struct is_rv_or_same< boost::rv< T >, ThisT > { enum _ { value = true }; };
|
Chris@101
|
78
|
Chris@101
|
79 #endif
|
Chris@101
|
80
|
Chris@16
|
81 template< typename SignatureT >
|
Chris@16
|
82 class light_function;
|
Chris@16
|
83
|
Chris@16
|
84 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
85
|
Chris@16
|
86 template< typename ResultT, typename... ArgsT >
|
Chris@16
|
87 class light_function< ResultT (ArgsT...) >
|
Chris@16
|
88 {
|
Chris@16
|
89 typedef light_function this_type;
|
Chris@16
|
90 BOOST_COPYABLE_AND_MOVABLE(this_type)
|
Chris@16
|
91
|
Chris@16
|
92 public:
|
Chris@16
|
93 typedef ResultT result_type;
|
Chris@16
|
94
|
Chris@16
|
95 private:
|
Chris@16
|
96 struct impl_base
|
Chris@16
|
97 {
|
Chris@101
|
98 typedef result_type (*invoke_type)(void*, ArgsT...);
|
Chris@16
|
99 const invoke_type invoke;
|
Chris@16
|
100
|
Chris@101
|
101 typedef impl_base* (*clone_type)(const void*);
|
Chris@16
|
102 const clone_type clone;
|
Chris@16
|
103
|
Chris@101
|
104 typedef void (*destroy_type)(void*);
|
Chris@16
|
105 const destroy_type destroy;
|
Chris@16
|
106
|
Chris@16
|
107 impl_base(invoke_type inv, clone_type cl, destroy_type dstr) : invoke(inv), clone(cl), destroy(dstr)
|
Chris@16
|
108 {
|
Chris@16
|
109 }
|
Chris@101
|
110
|
Chris@101
|
111 BOOST_DELETED_FUNCTION(impl_base(impl_base const&))
|
Chris@101
|
112 BOOST_DELETED_FUNCTION(impl_base& operator= (impl_base const&))
|
Chris@16
|
113 };
|
Chris@16
|
114
|
Chris@16
|
115 #if !defined(BOOST_LOG_NO_MEMBER_TEMPLATE_FRIENDS)
|
Chris@16
|
116 template< typename FunT >
|
Chris@16
|
117 class impl;
|
Chris@16
|
118 template< typename FunT >
|
Chris@16
|
119 friend class impl;
|
Chris@16
|
120 #endif
|
Chris@16
|
121
|
Chris@16
|
122 template< typename FunT >
|
Chris@16
|
123 class impl :
|
Chris@16
|
124 public impl_base
|
Chris@16
|
125 {
|
Chris@16
|
126 typedef impl< FunT > this_type;
|
Chris@16
|
127
|
Chris@16
|
128 FunT m_Function;
|
Chris@16
|
129
|
Chris@16
|
130 public:
|
Chris@16
|
131 explicit impl(FunT const& fun) :
|
Chris@16
|
132 impl_base(&this_type::invoke_impl, &this_type::clone_impl, &this_type::destroy_impl),
|
Chris@16
|
133 m_Function(fun)
|
Chris@16
|
134 {
|
Chris@16
|
135 }
|
Chris@16
|
136
|
Chris@16
|
137 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
138 explicit impl(FunT&& fun) :
|
Chris@16
|
139 impl_base(&this_type::invoke_impl, &this_type::clone_impl, &this_type::destroy_impl),
|
Chris@101
|
140 m_Function(boost::move(fun))
|
Chris@16
|
141 {
|
Chris@16
|
142 }
|
Chris@16
|
143 #endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
144
|
Chris@101
|
145 static void destroy_impl(void* self)
|
Chris@16
|
146 {
|
Chris@101
|
147 delete static_cast< impl* >(static_cast< impl_base* >(self));
|
Chris@16
|
148 }
|
Chris@101
|
149 static impl_base* clone_impl(const void* self)
|
Chris@16
|
150 {
|
Chris@101
|
151 return new impl(static_cast< const impl* >(static_cast< const impl_base* >(self))->m_Function);
|
Chris@16
|
152 }
|
Chris@101
|
153 static result_type invoke_impl(void* self, ArgsT... args)
|
Chris@16
|
154 {
|
Chris@101
|
155 return static_cast< impl* >(static_cast< impl_base* >(self))->m_Function(args...);
|
Chris@16
|
156 }
|
Chris@101
|
157
|
Chris@101
|
158 BOOST_DELETED_FUNCTION(impl(impl const&))
|
Chris@101
|
159 BOOST_DELETED_FUNCTION(impl& operator= (impl const&))
|
Chris@16
|
160 };
|
Chris@16
|
161
|
Chris@16
|
162 private:
|
Chris@16
|
163 impl_base* m_pImpl;
|
Chris@16
|
164
|
Chris@16
|
165 public:
|
Chris@16
|
166 BOOST_CONSTEXPR light_function() BOOST_NOEXCEPT : m_pImpl(NULL)
|
Chris@16
|
167 {
|
Chris@16
|
168 }
|
Chris@16
|
169 light_function(this_type const& that)
|
Chris@16
|
170 {
|
Chris@16
|
171 if (that.m_pImpl)
|
Chris@16
|
172 m_pImpl = that.m_pImpl->clone(that.m_pImpl);
|
Chris@16
|
173 else
|
Chris@16
|
174 m_pImpl = NULL;
|
Chris@16
|
175 }
|
Chris@16
|
176
|
Chris@16
|
177 light_function(BOOST_RV_REF(this_type) that) BOOST_NOEXCEPT
|
Chris@16
|
178 {
|
Chris@16
|
179 m_pImpl = that.m_pImpl;
|
Chris@16
|
180 that.m_pImpl = NULL;
|
Chris@16
|
181 }
|
Chris@16
|
182
|
Chris@16
|
183 light_function(BOOST_RV_REF(const this_type) that) BOOST_NOEXCEPT
|
Chris@16
|
184 {
|
Chris@16
|
185 m_pImpl = that.m_pImpl;
|
Chris@16
|
186 ((this_type&)that).m_pImpl = NULL;
|
Chris@16
|
187 }
|
Chris@16
|
188
|
Chris@16
|
189 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
190 template< typename FunT >
|
Chris@16
|
191 light_function(FunT&& fun) :
|
Chris@16
|
192 m_pImpl(new impl< typename remove_cv< typename remove_reference< FunT >::type >::type >(boost::forward< FunT >(fun)))
|
Chris@16
|
193 {
|
Chris@16
|
194 }
|
Chris@16
|
195 #else
|
Chris@16
|
196 template< typename FunT >
|
Chris@101
|
197 light_function(FunT const& fun, typename disable_if_c< is_rv_or_same< FunT, this_type >::value, int >::type = 0) :
|
Chris@16
|
198 m_pImpl(new impl< FunT >(fun))
|
Chris@16
|
199 {
|
Chris@16
|
200 }
|
Chris@16
|
201 template< typename FunT >
|
Chris@101
|
202 light_function(BOOST_RV_REF(FunT) fun, typename disable_if_c< is_cv_same< FunT, this_type >::value, int >::type = 0) :
|
Chris@16
|
203 m_pImpl(new impl< typename remove_cv< FunT >::type >(fun))
|
Chris@16
|
204 {
|
Chris@16
|
205 }
|
Chris@16
|
206 #endif
|
Chris@16
|
207
|
Chris@16
|
208 //! Constructor from NULL
|
Chris@16
|
209 #if !defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
210 BOOST_CONSTEXPR light_function(std::nullptr_t) BOOST_NOEXCEPT
|
Chris@16
|
211 #else
|
Chris@16
|
212 BOOST_CONSTEXPR light_function(int p) BOOST_NOEXCEPT
|
Chris@16
|
213 #endif
|
Chris@16
|
214 : m_pImpl(NULL)
|
Chris@16
|
215 {
|
Chris@16
|
216 #if defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
217 BOOST_ASSERT(p == 0);
|
Chris@16
|
218 #endif
|
Chris@16
|
219 }
|
Chris@16
|
220 ~light_function()
|
Chris@16
|
221 {
|
Chris@16
|
222 clear();
|
Chris@16
|
223 }
|
Chris@16
|
224
|
Chris@16
|
225 light_function& operator= (BOOST_RV_REF(this_type) that) BOOST_NOEXCEPT
|
Chris@16
|
226 {
|
Chris@16
|
227 this->swap(that);
|
Chris@16
|
228 return *this;
|
Chris@16
|
229 }
|
Chris@16
|
230 light_function& operator= (BOOST_COPY_ASSIGN_REF(this_type) that)
|
Chris@16
|
231 {
|
Chris@101
|
232 light_function tmp = static_cast< this_type const& >(that);
|
Chris@16
|
233 this->swap(tmp);
|
Chris@16
|
234 return *this;
|
Chris@16
|
235 }
|
Chris@16
|
236 //! Assignment of NULL
|
Chris@16
|
237 #if !defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
238 light_function& operator= (std::nullptr_t)
|
Chris@16
|
239 #else
|
Chris@16
|
240 light_function& operator= (int p)
|
Chris@16
|
241 #endif
|
Chris@16
|
242 {
|
Chris@16
|
243 #if defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
244 BOOST_ASSERT(p == 0);
|
Chris@16
|
245 #endif
|
Chris@16
|
246 clear();
|
Chris@16
|
247 return *this;
|
Chris@16
|
248 }
|
Chris@16
|
249 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
250 template< typename FunT >
|
Chris@16
|
251 light_function& operator= (FunT&& fun)
|
Chris@16
|
252 {
|
Chris@16
|
253 light_function tmp(boost::forward< FunT >(fun));
|
Chris@16
|
254 this->swap(tmp);
|
Chris@16
|
255 return *this;
|
Chris@16
|
256 }
|
Chris@16
|
257 #else
|
Chris@16
|
258 template< typename FunT >
|
Chris@101
|
259 typename disable_if_c< is_rv_or_same< FunT, this_type >::value, this_type& >::type
|
Chris@16
|
260 operator= (FunT const& fun)
|
Chris@16
|
261 {
|
Chris@16
|
262 light_function tmp(fun);
|
Chris@16
|
263 this->swap(tmp);
|
Chris@16
|
264 return *this;
|
Chris@16
|
265 }
|
Chris@16
|
266 #endif
|
Chris@16
|
267
|
Chris@16
|
268 result_type operator() (ArgsT... args) const
|
Chris@16
|
269 {
|
Chris@16
|
270 return m_pImpl->invoke(m_pImpl, args...);
|
Chris@16
|
271 }
|
Chris@16
|
272
|
Chris@101
|
273 BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
|
Chris@16
|
274 bool operator! () const BOOST_NOEXCEPT { return (m_pImpl == NULL); }
|
Chris@16
|
275 bool empty() const BOOST_NOEXCEPT { return (m_pImpl == NULL); }
|
Chris@16
|
276 void clear() BOOST_NOEXCEPT
|
Chris@16
|
277 {
|
Chris@16
|
278 if (m_pImpl)
|
Chris@16
|
279 {
|
Chris@16
|
280 m_pImpl->destroy(m_pImpl);
|
Chris@16
|
281 m_pImpl = NULL;
|
Chris@16
|
282 }
|
Chris@16
|
283 }
|
Chris@16
|
284
|
Chris@16
|
285 void swap(this_type& that) BOOST_NOEXCEPT
|
Chris@16
|
286 {
|
Chris@101
|
287 impl_base* p = m_pImpl;
|
Chris@16
|
288 m_pImpl = that.m_pImpl;
|
Chris@16
|
289 that.m_pImpl = p;
|
Chris@16
|
290 }
|
Chris@16
|
291 };
|
Chris@16
|
292
|
Chris@16
|
293 template< typename... ArgsT >
|
Chris@16
|
294 class light_function< void (ArgsT...) >
|
Chris@16
|
295 {
|
Chris@16
|
296 typedef light_function this_type;
|
Chris@16
|
297 BOOST_COPYABLE_AND_MOVABLE(this_type)
|
Chris@16
|
298
|
Chris@16
|
299 public:
|
Chris@16
|
300 typedef void result_type;
|
Chris@16
|
301
|
Chris@16
|
302 private:
|
Chris@16
|
303 struct impl_base
|
Chris@16
|
304 {
|
Chris@101
|
305 typedef void (*invoke_type)(void*, ArgsT...);
|
Chris@16
|
306 const invoke_type invoke;
|
Chris@16
|
307
|
Chris@101
|
308 typedef impl_base* (*clone_type)(const void*);
|
Chris@16
|
309 const clone_type clone;
|
Chris@16
|
310
|
Chris@101
|
311 typedef void (*destroy_type)(void*);
|
Chris@16
|
312 const destroy_type destroy;
|
Chris@16
|
313
|
Chris@16
|
314 impl_base(invoke_type inv, clone_type cl, destroy_type dstr) : invoke(inv), clone(cl), destroy(dstr)
|
Chris@16
|
315 {
|
Chris@16
|
316 }
|
Chris@101
|
317
|
Chris@101
|
318 BOOST_DELETED_FUNCTION(impl_base(impl_base const&))
|
Chris@101
|
319 BOOST_DELETED_FUNCTION(impl_base& operator= (impl_base const&))
|
Chris@16
|
320 };
|
Chris@16
|
321
|
Chris@16
|
322 #if !defined(BOOST_LOG_NO_MEMBER_TEMPLATE_FRIENDS)
|
Chris@16
|
323 template< typename FunT >
|
Chris@16
|
324 class impl;
|
Chris@16
|
325 template< typename FunT >
|
Chris@16
|
326 friend class impl;
|
Chris@16
|
327 #endif
|
Chris@16
|
328
|
Chris@16
|
329 template< typename FunT >
|
Chris@16
|
330 class impl :
|
Chris@16
|
331 public impl_base
|
Chris@16
|
332 {
|
Chris@16
|
333 typedef impl< FunT > this_type;
|
Chris@16
|
334
|
Chris@16
|
335 FunT m_Function;
|
Chris@16
|
336
|
Chris@16
|
337 public:
|
Chris@16
|
338 explicit impl(FunT const& fun) :
|
Chris@16
|
339 impl_base(&this_type::invoke_impl, &this_type::clone_impl, &this_type::destroy_impl),
|
Chris@16
|
340 m_Function(fun)
|
Chris@16
|
341 {
|
Chris@16
|
342 }
|
Chris@16
|
343
|
Chris@16
|
344 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
345 explicit impl(FunT&& fun) :
|
Chris@16
|
346 impl_base(&this_type::invoke_impl, &this_type::clone_impl, &this_type::destroy_impl),
|
Chris@101
|
347 m_Function(boost::move(fun))
|
Chris@16
|
348 {
|
Chris@16
|
349 }
|
Chris@16
|
350 #endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
351
|
Chris@101
|
352 static void destroy_impl(void* self)
|
Chris@16
|
353 {
|
Chris@101
|
354 delete static_cast< impl* >(static_cast< impl_base* >(self));
|
Chris@16
|
355 }
|
Chris@101
|
356 static impl_base* clone_impl(const void* self)
|
Chris@16
|
357 {
|
Chris@101
|
358 return new impl(static_cast< const impl* >(static_cast< const impl_base* >(self))->m_Function);
|
Chris@16
|
359 }
|
Chris@101
|
360 static result_type invoke_impl(void* self, ArgsT... args)
|
Chris@16
|
361 {
|
Chris@101
|
362 static_cast< impl* >(static_cast< impl_base* >(self))->m_Function(args...);
|
Chris@16
|
363 }
|
Chris@101
|
364
|
Chris@101
|
365 BOOST_DELETED_FUNCTION(impl(impl const&))
|
Chris@101
|
366 BOOST_DELETED_FUNCTION(impl& operator= (impl const&))
|
Chris@16
|
367 };
|
Chris@16
|
368
|
Chris@16
|
369 private:
|
Chris@16
|
370 impl_base* m_pImpl;
|
Chris@16
|
371
|
Chris@16
|
372 public:
|
Chris@16
|
373 BOOST_CONSTEXPR light_function() BOOST_NOEXCEPT : m_pImpl(NULL)
|
Chris@16
|
374 {
|
Chris@16
|
375 }
|
Chris@16
|
376 light_function(this_type const& that)
|
Chris@16
|
377 {
|
Chris@16
|
378 if (that.m_pImpl)
|
Chris@16
|
379 m_pImpl = that.m_pImpl->clone(that.m_pImpl);
|
Chris@16
|
380 else
|
Chris@16
|
381 m_pImpl = NULL;
|
Chris@16
|
382 }
|
Chris@16
|
383 light_function(BOOST_RV_REF(this_type) that) BOOST_NOEXCEPT
|
Chris@16
|
384 {
|
Chris@16
|
385 m_pImpl = that.m_pImpl;
|
Chris@16
|
386 that.m_pImpl = NULL;
|
Chris@16
|
387 }
|
Chris@16
|
388
|
Chris@16
|
389 light_function(BOOST_RV_REF(const this_type) that) BOOST_NOEXCEPT
|
Chris@16
|
390 {
|
Chris@16
|
391 m_pImpl = that.m_pImpl;
|
Chris@16
|
392 ((this_type&)that).m_pImpl = NULL;
|
Chris@16
|
393 }
|
Chris@16
|
394
|
Chris@16
|
395 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
396 template< typename FunT >
|
Chris@16
|
397 light_function(FunT&& fun) :
|
Chris@16
|
398 m_pImpl(new impl< typename remove_cv< typename remove_reference< FunT >::type >::type >(boost::forward< FunT >(fun)))
|
Chris@16
|
399 {
|
Chris@16
|
400 }
|
Chris@16
|
401 #else
|
Chris@16
|
402 template< typename FunT >
|
Chris@101
|
403 light_function(FunT const& fun, typename disable_if_c< is_rv_or_same< FunT, this_type >::value, int >::type = 0) :
|
Chris@16
|
404 m_pImpl(new impl< FunT >(fun))
|
Chris@16
|
405 {
|
Chris@16
|
406 }
|
Chris@16
|
407 template< typename FunT >
|
Chris@101
|
408 light_function(BOOST_RV_REF(FunT) fun, typename disable_if_c< is_cv_same< FunT, this_type >::value, int >::type = 0) :
|
Chris@16
|
409 m_pImpl(new impl< typename remove_cv< FunT >::type >(fun))
|
Chris@16
|
410 {
|
Chris@16
|
411 }
|
Chris@16
|
412 #endif
|
Chris@16
|
413
|
Chris@16
|
414 //! Constructor from NULL
|
Chris@16
|
415 #if !defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
416 BOOST_CONSTEXPR light_function(std::nullptr_t) BOOST_NOEXCEPT
|
Chris@16
|
417 #else
|
Chris@16
|
418 BOOST_CONSTEXPR light_function(int p) BOOST_NOEXCEPT
|
Chris@16
|
419 #endif
|
Chris@16
|
420 : m_pImpl(NULL)
|
Chris@16
|
421 {
|
Chris@16
|
422 #if defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
423 BOOST_ASSERT(p == 0);
|
Chris@16
|
424 #endif
|
Chris@16
|
425 }
|
Chris@16
|
426 ~light_function()
|
Chris@16
|
427 {
|
Chris@16
|
428 clear();
|
Chris@16
|
429 }
|
Chris@16
|
430
|
Chris@16
|
431 light_function& operator= (BOOST_RV_REF(this_type) that) BOOST_NOEXCEPT
|
Chris@16
|
432 {
|
Chris@16
|
433 this->swap(that);
|
Chris@16
|
434 return *this;
|
Chris@16
|
435 }
|
Chris@16
|
436 light_function& operator= (BOOST_COPY_ASSIGN_REF(this_type) that)
|
Chris@16
|
437 {
|
Chris@101
|
438 light_function tmp = static_cast< this_type const& >(that);
|
Chris@16
|
439 this->swap(tmp);
|
Chris@16
|
440 return *this;
|
Chris@16
|
441 }
|
Chris@16
|
442 //! Assignment of NULL
|
Chris@16
|
443 #if !defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
444 light_function& operator= (std::nullptr_t)
|
Chris@16
|
445 #else
|
Chris@16
|
446 light_function& operator= (int p)
|
Chris@16
|
447 #endif
|
Chris@16
|
448 {
|
Chris@16
|
449 #if defined(BOOST_NO_CXX11_NULLPTR)
|
Chris@16
|
450 BOOST_ASSERT(p == 0);
|
Chris@16
|
451 #endif
|
Chris@16
|
452 clear();
|
Chris@16
|
453 return *this;
|
Chris@16
|
454 }
|
Chris@16
|
455 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
456 template< typename FunT >
|
Chris@16
|
457 light_function& operator= (FunT&& fun)
|
Chris@16
|
458 {
|
Chris@16
|
459 light_function tmp(boost::forward< FunT >(fun));
|
Chris@16
|
460 this->swap(tmp);
|
Chris@16
|
461 return *this;
|
Chris@16
|
462 }
|
Chris@16
|
463 #else
|
Chris@16
|
464 template< typename FunT >
|
Chris@101
|
465 typename disable_if_c< is_rv_or_same< FunT, this_type >::value, this_type& >::type
|
Chris@16
|
466 operator= (FunT const& fun)
|
Chris@16
|
467 {
|
Chris@16
|
468 light_function tmp(fun);
|
Chris@16
|
469 this->swap(tmp);
|
Chris@16
|
470 return *this;
|
Chris@16
|
471 }
|
Chris@16
|
472 #endif
|
Chris@16
|
473
|
Chris@16
|
474 result_type operator() (ArgsT... args) const
|
Chris@16
|
475 {
|
Chris@16
|
476 m_pImpl->invoke(m_pImpl, args...);
|
Chris@16
|
477 }
|
Chris@16
|
478
|
Chris@101
|
479 BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
|
Chris@16
|
480 bool operator! () const BOOST_NOEXCEPT { return (m_pImpl == NULL); }
|
Chris@16
|
481 bool empty() const BOOST_NOEXCEPT { return (m_pImpl == NULL); }
|
Chris@16
|
482 void clear() BOOST_NOEXCEPT
|
Chris@16
|
483 {
|
Chris@16
|
484 if (m_pImpl)
|
Chris@16
|
485 {
|
Chris@16
|
486 m_pImpl->destroy(m_pImpl);
|
Chris@16
|
487 m_pImpl = NULL;
|
Chris@16
|
488 }
|
Chris@16
|
489 }
|
Chris@16
|
490
|
Chris@16
|
491 void swap(this_type& that) BOOST_NOEXCEPT
|
Chris@16
|
492 {
|
Chris@101
|
493 impl_base* p = m_pImpl;
|
Chris@16
|
494 m_pImpl = that.m_pImpl;
|
Chris@16
|
495 that.m_pImpl = p;
|
Chris@16
|
496 }
|
Chris@16
|
497 };
|
Chris@16
|
498
|
Chris@16
|
499 #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
500
|
Chris@16
|
501 #define BOOST_PP_FILENAME_1 <boost/log/detail/light_function_pp.hpp>
|
Chris@16
|
502 #define BOOST_PP_ITERATION_LIMITS (0, BOOST_LOG_LIGHT_FUNCTION_LIMIT)
|
Chris@16
|
503 #include BOOST_PP_ITERATE()
|
Chris@16
|
504
|
Chris@16
|
505 #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
506
|
Chris@16
|
507 template< typename SignatureT >
|
Chris@16
|
508 inline void swap(light_function< SignatureT >& left, light_function< SignatureT >& right)
|
Chris@16
|
509 {
|
Chris@16
|
510 left.swap(right);
|
Chris@16
|
511 }
|
Chris@16
|
512
|
Chris@16
|
513 } // namespace aux
|
Chris@16
|
514
|
Chris@16
|
515 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
516
|
Chris@16
|
517 } // namespace boost
|
Chris@16
|
518
|
Chris@16
|
519 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
520
|
Chris@16
|
521 #endif // BOOST_LOG_DETAIL_LIGHT_FUNCTION_HPP_INCLUDED_
|