@@ -100,6 +100,8 @@ struct message_container;
100
100
*/
101
101
template <typename T>
102
102
struct message_container <T,true > : private T {
103
+ static constexpr bool is_value_movable =false ;
104
+
103
105
constexpr message_container (T&& t)
104
106
: T(std::move(t)) {
105
107
}
@@ -120,6 +122,8 @@ struct message_container<T, true> : private T {
120
122
*/
121
123
template <typename T>
122
124
struct message_container <T,false > {
125
+ static constexpr bool is_value_movable = std::is_move_constructible<T>::value;
126
+
123
127
constexpr message_container (T&& t)
124
128
: value_(std::move(t)) {
125
129
}
@@ -129,12 +133,16 @@ struct message_container<T, false> {
129
133
: value_(std::forward<Args>(args)...) {
130
134
}
131
135
132
- constexpr const T&data ()const {
136
+ constexpr const T&data ()const & {
133
137
return value_;
134
138
}
135
139
140
+ constexpr Tdata () && {
141
+ return std::move (value_);
142
+ }
143
+
136
144
private:
137
- const T value_;
145
+ T value_;
138
146
};
139
147
140
148
template <typename T>
@@ -283,9 +291,9 @@ class actor {
283
291
};
284
292
285
293
/* * Wrapper for member function pointers.*/
286
- template <typename M,typename C>
294
+ template <typename M,typename C, typename P >
287
295
class mem_handler_t :public handler_t {
288
- using F = std::function<void (C*, actor_ref,const M& )>;
296
+ using F = std::function<void (C*, actor_ref,P )>;
289
297
290
298
public:
291
299
mem_handler_t (F&& func, C* ptr)
@@ -294,8 +302,12 @@ class actor {
294
302
}
295
303
296
304
void invoke (std::unique_ptr<core::msg_t > msg)const override {
305
+ using message_reference_t =
306
+ typename std::conditional<core::msg_wrap_t <M>::is_value_movable,
307
+ core::msg_wrap_t <M>&&,const core::msg_wrap_t <M>&>::type;
308
+
297
309
func_ (ptr_,actor_ref (msg->sender ,true ),
298
- static_cast <core:: msg_wrap_t <M>*>( msg.get ())-> data ());
310
+ static_cast <message_reference_t >(* msg.get ()). data ());
299
311
}
300
312
301
313
private:
@@ -341,13 +353,13 @@ class actor {
341
353
void die ();
342
354
343
355
// / Sets handler as member function pointer.
344
- template <typename M,typename ClassName>
345
- inline void handler (void (ClassName::*func)(actor_ref,const M& )) {
356
+ template <typename M,typename ClassName, typename P >
357
+ inline void handler (void (ClassName::*func)(actor_ref,P )) {
346
358
set_handler (
347
359
// Type of the handler.
348
360
std::type_index (typeid (M)),
349
361
// Callback.
350
- std::make_unique<mem_handler_t <M, ClassName>>(
362
+ std::make_unique<mem_handler_t <M, ClassName, P >>(
351
363
func,static_cast <ClassName*>(this )));
352
364
}
353
365