Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit60fd1cb

Browse files
committed
ability to move message value into handler
1 parent91a51bd commit60fd1cb

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

‎lib/acto.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ struct message_container;
100100
*/
101101
template<typename T>
102102
structmessage_container<T,true> : private T {
103+
staticconstexprbool is_value_movable =false;
104+
103105
constexprmessage_container(T&& t)
104106
: T(std::move(t)) {
105107
}
@@ -120,6 +122,8 @@ struct message_container<T, true> : private T {
120122
*/
121123
template<typename T>
122124
structmessage_container<T,false> {
125+
staticconstexprbool is_value_movable = std::is_move_constructible<T>::value;
126+
123127
constexprmessage_container(T&& t)
124128
: value_(std::move(t)) {
125129
}
@@ -129,12 +133,16 @@ struct message_container<T, false> {
129133
: value_(std::forward<Args>(args)...) {
130134
}
131135

132-
constexprconst T&data()const {
136+
constexprconst T&data()const& {
133137
return value_;
134138
}
135139

140+
constexpr Tdata() && {
141+
returnstd::move(value_);
142+
}
143+
136144
private:
137-
constT value_;
145+
T value_;
138146
};
139147

140148
template<typename T>
@@ -283,9 +291,9 @@ class actor {
283291
};
284292

285293
/** Wrapper for member function pointers.*/
286-
template<typename M,typename C>
294+
template<typename M,typename C,typename P>
287295
classmem_handler_t :publichandler_t {
288-
using F = std::function<void(C*, actor_ref,const M&)>;
296+
using F = std::function<void(C*, actor_ref,P)>;
289297

290298
public:
291299
mem_handler_t(F&& func, C* ptr)
@@ -294,8 +302,12 @@ class actor {
294302
}
295303

296304
voidinvoke(std::unique_ptr<core::msg_t> msg)constoverride {
305+
usingmessage_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+
297309
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());
299311
}
300312

301313
private:
@@ -341,13 +353,13 @@ class actor {
341353
voiddie();
342354

343355
/// Sets handler as member function pointer.
344-
template<typename M,typename ClassName>
345-
inlinevoidhandler(void (ClassName::*func)(actor_ref,const M&)) {
356+
template<typename M,typename ClassName,typename P>
357+
inlinevoidhandler(void (ClassName::*func)(actor_ref,P)) {
346358
set_handler(
347359
// Type of the handler.
348360
std::type_index(typeid(M)),
349361
// Callback.
350-
std::make_unique<mem_handler_t<M, ClassName>>(
362+
std::make_unique<mem_handler_t<M, ClassName, P>>(
351363
func,static_cast<ClassName*>(this)));
352364
}
353365

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp