|
12 | 12 | /// sending a clone of the object to the destination thread message queue. The destination |
13 | 13 | /// thread calls `Invoke()` to invoke the target function. |
14 | 14 | /// |
| 15 | +/// Argument data is created on the heap using `operator new` for transport thought a thread |
| 16 | +/// message queue. An optional fixed-block allocator is available. See `USE_ALLOCATOR`. |
| 17 | +/// |
15 | 18 | /// `RetType operator()(Args... args)` - called by the source thread to initiate the async |
16 | | -/// function call. May throw `std::bad_alloc` if dynamic storage allocation fails and USE_ASSERTS |
17 | | -/// is not defined. Clone() may also throw `std::bad_alloc`. All other delegate class functions do |
18 | | -/// not throw exceptions. |
| 19 | +/// function call. May throw `std::bad_alloc` if dynamic storage allocation fails and `USE_ASSERTS` |
| 20 | +/// is not defined. Clone() may also throw `std::bad_alloc` unless `USE_ASSERTS`. All other delegate |
| 21 | +/// class functions do not throw exceptions. |
19 | 22 | /// |
20 | 23 | /// `void Invoke(std::shared_ptr<DelegateMsg> msg)` - called by the destination |
21 | 24 | /// thread to invoke the target function. The destination thread must not call any other |
|
49 | 52 |
|
50 | 53 | namespace DelegateLib { |
51 | 54 |
|
| 55 | +// Helper trait to check if a type is a reference to a std::shared_ptr |
| 56 | +template <typename T> |
| 57 | +struct is_shared_ptr_reference : std::false_type {}; |
| 58 | + |
| 59 | +template <typename T> |
| 60 | +struct is_shared_ptr_reference<std::shared_ptr<T>&> : std::true_type {}; |
| 61 | + |
| 62 | +template <typename T> |
| 63 | +struct is_shared_ptr_reference<std::shared_ptr<T>*> : std::true_type {}; |
| 64 | + |
| 65 | +template <typename T> |
| 66 | +struct is_shared_ptr_reference<const std::shared_ptr<T>&> : std::true_type {}; |
| 67 | + |
| 68 | +template <typename T> |
| 69 | +struct is_shared_ptr_reference<const std::shared_ptr<T>* > : std::true_type {}; |
| 70 | + |
52 | 71 | /// @brief Stores all function arguments suitable for non-blocking asynchronous calls. |
53 | 72 | /// Argument data is stored in the heap. |
54 | 73 | /// @tparam Args The argument types of the bound delegate function. |
@@ -265,8 +284,8 @@ class DelegateFreeAsync<RetType(Args...)> : public DelegateFree<RetType(Args...) |
265 | 284 | // undefined. In other words: |
266 | 285 | // void MyFunc(std::shared_ptr<T> data) // Ok! |
267 | 286 | // void MyFunc(std::shared_ptr<T>& data) // Error if DelegateAsync or DelegateSpAsync target! |
268 | | - static_assert(!(std::disjunction_v<is_shared_ptr<Args>...> && |
269 | | - (std::disjunction_v<std::is_lvalue_reference<Args>, std::is_pointer<Args>> || ...)), |
| 287 | + static_assert(!( |
| 288 | + std::disjunction_v<is_shared_ptr_reference<Args>...>), |
270 | 289 | "std::shared_ptr reference argument not allowed"); |
271 | 290 | } |
272 | 291 | } |
@@ -565,8 +584,8 @@ class DelegateMemberAsync<TClass, RetType(Args...)> : public DelegateMember<TCla |
565 | 584 | // undefined. In other words: |
566 | 585 | // void MyFunc(std::shared_ptr<T> data) // Ok! |
567 | 586 | // void MyFunc(std::shared_ptr<T>& data) // Error if DelegateAsync or DelegateSpAsync target! |
568 | | - static_assert(!(std::disjunction_v<is_shared_ptr<Args>...> && |
569 | | - (std::disjunction_v<std::is_lvalue_reference<Args>, std::is_pointer<Args>> || ...)), |
| 587 | + static_assert(!( |
| 588 | + std::disjunction_v<is_shared_ptr_reference<Args>...>), |
570 | 589 | "std::shared_ptr reference argument not allowed"); |
571 | 590 | } |
572 | 591 | } |
@@ -806,8 +825,8 @@ class DelegateFunctionAsync<RetType(Args...)> : public DelegateFunction<RetType( |
806 | 825 | // undefined. In other words: |
807 | 826 | // void MyFunc(std::shared_ptr<T> data) // Ok! |
808 | 827 | // void MyFunc(std::shared_ptr<T>& data) // Error if DelegateAsync or DelegateSpAsync target! |
809 | | - static_assert(!(std::disjunction_v<is_shared_ptr<Args>...> && |
810 | | - (std::disjunction_v<std::is_lvalue_reference<Args>, std::is_pointer<Args>> || ...)), |
| 828 | + static_assert(!( |
| 829 | + std::disjunction_v<is_shared_ptr_reference<Args>...>), |
811 | 830 | "std::shared_ptr reference argument not allowed"); |
812 | 831 | } |
813 | 832 | } |
|
0 commit comments