comparison DEPENDENCIES/generic/include/boost/log/detail/light_function.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
1 /* 1 /*
2 * Copyright Andrey Semashev 2007 - 2013. 2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0. 3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at 4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt) 5 * http://www.boost.org/LICENSE_1_0.txt)
6 */ 6 */
7 /*! 7 /*!
32 #include <boost/preprocessor/repetition/enum_trailing_params.hpp> 32 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
33 #include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp> 33 #include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
34 #endif 34 #endif
35 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 35 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
36 #include <boost/utility/enable_if.hpp> 36 #include <boost/utility/enable_if.hpp>
37 #include <boost/type_traits/is_same.hpp>
38 #include <boost/mpl/or.hpp>
39 #else 37 #else
40 #include <boost/type_traits/remove_reference.hpp> 38 #include <boost/type_traits/remove_reference.hpp>
41 #endif 39 #endif
42 #if defined(BOOST_NO_CXX11_NULLPTR) 40 #if defined(BOOST_NO_CXX11_NULLPTR)
43 #include <boost/assert.hpp> 41 #include <boost/assert.hpp>
55 namespace boost { 53 namespace boost {
56 54
57 BOOST_LOG_OPEN_NAMESPACE 55 BOOST_LOG_OPEN_NAMESPACE
58 56
59 namespace aux { 57 namespace aux {
58
59 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
60
61 template< typename T, typename ThisT >
62 struct is_cv_same { enum _ { value = false }; };
63 template< typename T >
64 struct is_cv_same< T, T > { enum _ { value = true }; };
65 template< typename T >
66 struct is_cv_same< T, const T > { enum _ { value = true }; };
67 template< typename T >
68 struct is_cv_same< T, volatile T > { enum _ { value = true }; };
69 template< typename T >
70 struct is_cv_same< T, const volatile T > { enum _ { value = true }; };
71
72 template< typename T, typename ThisT >
73 struct is_rv_or_same { enum _ { value = false }; };
74 template< typename T >
75 struct is_rv_or_same< T, T > { enum _ { value = true }; };
76 template< typename T, typename ThisT >
77 struct is_rv_or_same< boost::rv< T >, ThisT > { enum _ { value = true }; };
78
79 #endif
60 80
61 template< typename SignatureT > 81 template< typename SignatureT >
62 class light_function; 82 class light_function;
63 83
64 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) 84 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
73 typedef ResultT result_type; 93 typedef ResultT result_type;
74 94
75 private: 95 private:
76 struct impl_base 96 struct impl_base
77 { 97 {
78 typedef result_type (*invoke_type)(impl_base*, ArgsT...); 98 typedef result_type (*invoke_type)(void*, ArgsT...);
79 const invoke_type invoke; 99 const invoke_type invoke;
80 100
81 typedef impl_base* (*clone_type)(const impl_base*); 101 typedef impl_base* (*clone_type)(const void*);
82 const clone_type clone; 102 const clone_type clone;
83 103
84 typedef void (*destroy_type)(impl_base*); 104 typedef void (*destroy_type)(void*);
85 const destroy_type destroy; 105 const destroy_type destroy;
86 106
87 impl_base(invoke_type inv, clone_type cl, destroy_type dstr) : invoke(inv), clone(cl), destroy(dstr) 107 impl_base(invoke_type inv, clone_type cl, destroy_type dstr) : invoke(inv), clone(cl), destroy(dstr)
88 { 108 {
89 } 109 }
110
111 BOOST_DELETED_FUNCTION(impl_base(impl_base const&))
112 BOOST_DELETED_FUNCTION(impl_base& operator= (impl_base const&))
90 }; 113 };
91 114
92 #if !defined(BOOST_LOG_NO_MEMBER_TEMPLATE_FRIENDS) 115 #if !defined(BOOST_LOG_NO_MEMBER_TEMPLATE_FRIENDS)
93 template< typename FunT > 116 template< typename FunT >
94 class impl; 117 class impl;
112 } 135 }
113 136
114 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 137 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
115 explicit impl(FunT&& fun) : 138 explicit impl(FunT&& fun) :
116 impl_base(&this_type::invoke_impl, &this_type::clone_impl, &this_type::destroy_impl), 139 impl_base(&this_type::invoke_impl, &this_type::clone_impl, &this_type::destroy_impl),
117 m_Function(fun) 140 m_Function(boost::move(fun))
118 { 141 {
119 } 142 }
120 #endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 143 #endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
121 144
122 static void destroy_impl(impl_base* self) 145 static void destroy_impl(void* self)
123 { 146 {
124 delete static_cast< impl* >(self); 147 delete static_cast< impl* >(static_cast< impl_base* >(self));
125 } 148 }
126 static impl_base* clone_impl(const impl_base* self) 149 static impl_base* clone_impl(const void* self)
127 { 150 {
128 return new impl(static_cast< const impl* >(self)->m_Function); 151 return new impl(static_cast< const impl* >(static_cast< const impl_base* >(self))->m_Function);
129 } 152 }
130 static result_type invoke_impl(impl_base* self, ArgsT... args) 153 static result_type invoke_impl(void* self, ArgsT... args)
131 { 154 {
132 return static_cast< impl* >(self)->m_Function(args...); 155 return static_cast< impl* >(static_cast< impl_base* >(self))->m_Function(args...);
133 } 156 }
157
158 BOOST_DELETED_FUNCTION(impl(impl const&))
159 BOOST_DELETED_FUNCTION(impl& operator= (impl const&))
134 }; 160 };
135 161
136 private: 162 private:
137 impl_base* m_pImpl; 163 impl_base* m_pImpl;
138 164
166 m_pImpl(new impl< typename remove_cv< typename remove_reference< FunT >::type >::type >(boost::forward< FunT >(fun))) 192 m_pImpl(new impl< typename remove_cv< typename remove_reference< FunT >::type >::type >(boost::forward< FunT >(fun)))
167 { 193 {
168 } 194 }
169 #else 195 #else
170 template< typename FunT > 196 template< typename FunT >
171 light_function(FunT const& fun, typename disable_if< mpl::or_< move_detail::is_rv< FunT >, is_same< FunT, this_type > >, int >::type = 0) : 197 light_function(FunT const& fun, typename disable_if_c< is_rv_or_same< FunT, this_type >::value, int >::type = 0) :
172 m_pImpl(new impl< FunT >(fun)) 198 m_pImpl(new impl< FunT >(fun))
173 { 199 {
174 } 200 }
175 template< typename FunT > 201 template< typename FunT >
176 light_function(rv< FunT > const& fun, typename disable_if< is_same< typename remove_cv< FunT >::type, this_type >, int >::type = 0) : 202 light_function(BOOST_RV_REF(FunT) fun, typename disable_if_c< is_cv_same< FunT, this_type >::value, int >::type = 0) :
177 m_pImpl(new impl< typename remove_cv< FunT >::type >(fun)) 203 m_pImpl(new impl< typename remove_cv< FunT >::type >(fun))
178 { 204 {
179 } 205 }
180 #endif 206 #endif
181 207
201 this->swap(that); 227 this->swap(that);
202 return *this; 228 return *this;
203 } 229 }
204 light_function& operator= (BOOST_COPY_ASSIGN_REF(this_type) that) 230 light_function& operator= (BOOST_COPY_ASSIGN_REF(this_type) that)
205 { 231 {
206 light_function tmp(that); 232 light_function tmp = static_cast< this_type const& >(that);
207 this->swap(tmp); 233 this->swap(tmp);
208 return *this; 234 return *this;
209 } 235 }
210 //! Assignment of NULL 236 //! Assignment of NULL
211 #if !defined(BOOST_NO_CXX11_NULLPTR) 237 #if !defined(BOOST_NO_CXX11_NULLPTR)
228 this->swap(tmp); 254 this->swap(tmp);
229 return *this; 255 return *this;
230 } 256 }
231 #else 257 #else
232 template< typename FunT > 258 template< typename FunT >
233 typename disable_if< mpl::or_< move_detail::is_rv< FunT >, is_same< FunT, this_type > >, this_type& >::type 259 typename disable_if_c< is_rv_or_same< FunT, this_type >::value, this_type& >::type
234 operator= (FunT const& fun) 260 operator= (FunT const& fun)
235 { 261 {
236 light_function tmp(fun); 262 light_function tmp(fun);
237 this->swap(tmp); 263 this->swap(tmp);
238 return *this; 264 return *this;
242 result_type operator() (ArgsT... args) const 268 result_type operator() (ArgsT... args) const
243 { 269 {
244 return m_pImpl->invoke(m_pImpl, args...); 270 return m_pImpl->invoke(m_pImpl, args...);
245 } 271 }
246 272
247 BOOST_EXPLICIT_OPERATOR_BOOL() 273 BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
248 bool operator! () const BOOST_NOEXCEPT { return (m_pImpl == NULL); } 274 bool operator! () const BOOST_NOEXCEPT { return (m_pImpl == NULL); }
249 bool empty() const BOOST_NOEXCEPT { return (m_pImpl == NULL); } 275 bool empty() const BOOST_NOEXCEPT { return (m_pImpl == NULL); }
250 void clear() BOOST_NOEXCEPT 276 void clear() BOOST_NOEXCEPT
251 { 277 {
252 if (m_pImpl) 278 if (m_pImpl)
256 } 282 }
257 } 283 }
258 284
259 void swap(this_type& that) BOOST_NOEXCEPT 285 void swap(this_type& that) BOOST_NOEXCEPT
260 { 286 {
261 register impl_base* p = m_pImpl; 287 impl_base* p = m_pImpl;
262 m_pImpl = that.m_pImpl; 288 m_pImpl = that.m_pImpl;
263 that.m_pImpl = p; 289 that.m_pImpl = p;
264 } 290 }
265 }; 291 };
266 292
274 typedef void result_type; 300 typedef void result_type;
275 301
276 private: 302 private:
277 struct impl_base 303 struct impl_base
278 { 304 {
279 typedef void (*invoke_type)(impl_base*, ArgsT...); 305 typedef void (*invoke_type)(void*, ArgsT...);
280 const invoke_type invoke; 306 const invoke_type invoke;
281 307
282 typedef impl_base* (*clone_type)(const impl_base*); 308 typedef impl_base* (*clone_type)(const void*);
283 const clone_type clone; 309 const clone_type clone;
284 310
285 typedef void (*destroy_type)(impl_base*); 311 typedef void (*destroy_type)(void*);
286 const destroy_type destroy; 312 const destroy_type destroy;
287 313
288 impl_base(invoke_type inv, clone_type cl, destroy_type dstr) : invoke(inv), clone(cl), destroy(dstr) 314 impl_base(invoke_type inv, clone_type cl, destroy_type dstr) : invoke(inv), clone(cl), destroy(dstr)
289 { 315 {
290 } 316 }
317
318 BOOST_DELETED_FUNCTION(impl_base(impl_base const&))
319 BOOST_DELETED_FUNCTION(impl_base& operator= (impl_base const&))
291 }; 320 };
292 321
293 #if !defined(BOOST_LOG_NO_MEMBER_TEMPLATE_FRIENDS) 322 #if !defined(BOOST_LOG_NO_MEMBER_TEMPLATE_FRIENDS)
294 template< typename FunT > 323 template< typename FunT >
295 class impl; 324 class impl;
313 } 342 }
314 343
315 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 344 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
316 explicit impl(FunT&& fun) : 345 explicit impl(FunT&& fun) :
317 impl_base(&this_type::invoke_impl, &this_type::clone_impl, &this_type::destroy_impl), 346 impl_base(&this_type::invoke_impl, &this_type::clone_impl, &this_type::destroy_impl),
318 m_Function(fun) 347 m_Function(boost::move(fun))
319 { 348 {
320 } 349 }
321 #endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 350 #endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
322 351
323 static void destroy_impl(impl_base* self) 352 static void destroy_impl(void* self)
324 { 353 {
325 delete static_cast< impl* >(self); 354 delete static_cast< impl* >(static_cast< impl_base* >(self));
326 } 355 }
327 static impl_base* clone_impl(const impl_base* self) 356 static impl_base* clone_impl(const void* self)
328 { 357 {
329 return new impl(static_cast< const impl* >(self)->m_Function); 358 return new impl(static_cast< const impl* >(static_cast< const impl_base* >(self))->m_Function);
330 } 359 }
331 static result_type invoke_impl(impl_base* self, ArgsT... args) 360 static result_type invoke_impl(void* self, ArgsT... args)
332 { 361 {
333 static_cast< impl* >(self)->m_Function(args...); 362 static_cast< impl* >(static_cast< impl_base* >(self))->m_Function(args...);
334 } 363 }
364
365 BOOST_DELETED_FUNCTION(impl(impl const&))
366 BOOST_DELETED_FUNCTION(impl& operator= (impl const&))
335 }; 367 };
336 368
337 private: 369 private:
338 impl_base* m_pImpl; 370 impl_base* m_pImpl;
339 371
366 m_pImpl(new impl< typename remove_cv< typename remove_reference< FunT >::type >::type >(boost::forward< FunT >(fun))) 398 m_pImpl(new impl< typename remove_cv< typename remove_reference< FunT >::type >::type >(boost::forward< FunT >(fun)))
367 { 399 {
368 } 400 }
369 #else 401 #else
370 template< typename FunT > 402 template< typename FunT >
371 light_function(FunT const& fun, typename disable_if< mpl::or_< move_detail::is_rv< FunT >, is_same< FunT, this_type > >, int >::type = 0) : 403 light_function(FunT const& fun, typename disable_if_c< is_rv_or_same< FunT, this_type >::value, int >::type = 0) :
372 m_pImpl(new impl< FunT >(fun)) 404 m_pImpl(new impl< FunT >(fun))
373 { 405 {
374 } 406 }
375 template< typename FunT > 407 template< typename FunT >
376 light_function(rv< FunT > const& fun, typename disable_if< is_same< typename remove_cv< FunT >::type, this_type >, int >::type = 0) : 408 light_function(BOOST_RV_REF(FunT) fun, typename disable_if_c< is_cv_same< FunT, this_type >::value, int >::type = 0) :
377 m_pImpl(new impl< typename remove_cv< FunT >::type >(fun)) 409 m_pImpl(new impl< typename remove_cv< FunT >::type >(fun))
378 { 410 {
379 } 411 }
380 #endif 412 #endif
381 413
401 this->swap(that); 433 this->swap(that);
402 return *this; 434 return *this;
403 } 435 }
404 light_function& operator= (BOOST_COPY_ASSIGN_REF(this_type) that) 436 light_function& operator= (BOOST_COPY_ASSIGN_REF(this_type) that)
405 { 437 {
406 light_function tmp = that; 438 light_function tmp = static_cast< this_type const& >(that);
407 this->swap(tmp); 439 this->swap(tmp);
408 return *this; 440 return *this;
409 } 441 }
410 //! Assignment of NULL 442 //! Assignment of NULL
411 #if !defined(BOOST_NO_CXX11_NULLPTR) 443 #if !defined(BOOST_NO_CXX11_NULLPTR)
428 this->swap(tmp); 460 this->swap(tmp);
429 return *this; 461 return *this;
430 } 462 }
431 #else 463 #else
432 template< typename FunT > 464 template< typename FunT >
433 typename disable_if< mpl::or_< move_detail::is_rv< FunT >, is_same< FunT, this_type > >, this_type& >::type 465 typename disable_if_c< is_rv_or_same< FunT, this_type >::value, this_type& >::type
434 operator= (FunT const& fun) 466 operator= (FunT const& fun)
435 { 467 {
436 light_function tmp(fun); 468 light_function tmp(fun);
437 this->swap(tmp); 469 this->swap(tmp);
438 return *this; 470 return *this;
442 result_type operator() (ArgsT... args) const 474 result_type operator() (ArgsT... args) const
443 { 475 {
444 m_pImpl->invoke(m_pImpl, args...); 476 m_pImpl->invoke(m_pImpl, args...);
445 } 477 }
446 478
447 BOOST_EXPLICIT_OPERATOR_BOOL() 479 BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
448 bool operator! () const BOOST_NOEXCEPT { return (m_pImpl == NULL); } 480 bool operator! () const BOOST_NOEXCEPT { return (m_pImpl == NULL); }
449 bool empty() const BOOST_NOEXCEPT { return (m_pImpl == NULL); } 481 bool empty() const BOOST_NOEXCEPT { return (m_pImpl == NULL); }
450 void clear() BOOST_NOEXCEPT 482 void clear() BOOST_NOEXCEPT
451 { 483 {
452 if (m_pImpl) 484 if (m_pImpl)
456 } 488 }
457 } 489 }
458 490
459 void swap(this_type& that) BOOST_NOEXCEPT 491 void swap(this_type& that) BOOST_NOEXCEPT
460 { 492 {
461 register impl_base* p = m_pImpl; 493 impl_base* p = m_pImpl;
462 m_pImpl = that.m_pImpl; 494 m_pImpl = that.m_pImpl;
463 that.m_pImpl = p; 495 that.m_pImpl = p;
464 } 496 }
465 }; 497 };
466 498