Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Allow for constructing nested messages from other messages #173
Comments
|
I think the more general term for this would be |
|
Yeah, I can see that concatenation does the trick in this case as well. But do you purposefully want to restrict yourself to concatenation at the message boundary? Consider the messages Not sure if |
|
Messages are type-erased. You simply cannot provide any meaningful overload for |
|
Right, in order for |
|
I just realized that a |
|
Keep in mind, though, that you're copying out of the message when using |
|
Uh, that's really useful to know! |
|
Wait, the implementation looks like this: /**
* Returns the value at @p as instance of @p T.
*/
template <class T>
inline const T& get_as(size_t p) const {
CAF_REQUIRE(*(type_at(p)) == typeid(T));
return *reinterpret_cast<const T*>(at(p));
}Where's the copy taking place? |
|
In your example, you've used |
|
Got it. I thought you implied that |
|
What about something like Here's an example snippet: auto msg1 = make_message(1, 2, 3);
auto msg2 = make_message(4, 5, 6);
auto msg3 = message::concat(msg1.drop(1), msg2.take(2));
assert(msg3 == make_message(2, 3, 4, 5)); |
|
Looks good to me. That's the final piece missing to make it possible slicing message values arbitrarily without copying. |
Its now possible to concat messages, to do so you can use the `message::concat(message other)` or the `+` operator. Closes #173
Its now possible to concat messages, to do so you can use the `message::concat(message other)` or the `+` operator. Closes #173
Its now possible to concat messages, to do so you can use the `message::concat(message other)` or the `+` operator. Closes #173
It would be nice to have the ability to next messages. Here is a fictitious example:
The scenario is that a data structure with an expensive copy constructor exists already as a message (and thus internally as a reference-counted object). Then I'd like to be able to still reuse it in differently typed messages. It appears to be already possible to nest messages and extract them via
apply, but as a user, I don't want to work with this extra level of type-erased indirection. Rather, I'd like to directly reuse the value. In the above example, the send statement with the fictitiousunwrapwould create a message of type<expensive, int>as opposed to<message, int>. I'm not saying that anunwrapfunction is the right primitive, but I hope it illustrates the point.