Commit a0d0ab45 authored by Dominik Charousset's avatar Dominik Charousset

Enable conversion from typed views to handles

parent 6b0cb27c
...@@ -91,6 +91,9 @@ is based on [Keep a Changelog](https://keepachangelog.com). ...@@ -91,6 +91,9 @@ is based on [Keep a Changelog](https://keepachangelog.com).
already did. already did.
- The `typed_actor_view` decorator lacked several member functions such as - The `typed_actor_view` decorator lacked several member functions such as
`link_to`, `send_exit`, etc. These are now available. `link_to`, `send_exit`, etc. These are now available.
- Constructing a `typed_actor` handle from a pointer view failed du to a missing
constructor overload. This (explicit) overload now exists and the conversion
should work as expected.
## [0.17.5] - Unreleased ## [0.17.5] - Unreleased
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "caf/make_actor.hpp" #include "caf/make_actor.hpp"
#include "caf/replies_to.hpp" #include "caf/replies_to.hpp"
#include "caf/stateful_actor.hpp" #include "caf/stateful_actor.hpp"
#include "caf/typed_actor_view_base.hpp"
#include "caf/typed_behavior.hpp" #include "caf/typed_behavior.hpp"
#include "caf/typed_response_promise.hpp" #include "caf/typed_response_promise.hpp"
...@@ -148,6 +149,15 @@ public: ...@@ -148,6 +149,15 @@ public:
CAF_ASSERT(ptr != nullptr); CAF_ASSERT(ptr != nullptr);
} }
// Enable `handle_type{self}` for typed actor views.
template <class T, class = std::enable_if_t<
std::is_base_of<typed_actor_view_base, T>::value>>
explicit typed_actor(T ptr) : ptr_(ptr.internal_ptr()) {
static_assert(
detail::tl_subset_of<signatures, typename T::signatures>::value,
"Cannot assign T to incompatible handle type");
}
template <class... Ts> template <class... Ts>
typed_actor& operator=(const typed_actor<Ts...>& other) { typed_actor& operator=(const typed_actor<Ts...>& other) {
static_assert( static_assert(
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
namespace caf { namespace caf {
template <class... Sigs> template <class... Sigs>
class typed_actor_pointer { class typed_actor_pointer : public typed_actor_view_base {
public: public:
/// Stores the template parameter pack. /// Stores the template parameter pack.
using signatures = detail::type_list<Sigs...>; using signatures = detail::type_list<Sigs...>;
...@@ -45,6 +45,10 @@ public: ...@@ -45,6 +45,10 @@ public:
// nop // nop
} }
typed_actor_pointer(const typed_actor_pointer&) = default;
typed_actor_pointer& operator=(const typed_actor_pointer&) = default;
typed_actor_view<Sigs...>* operator->() { typed_actor_view<Sigs...>* operator->() {
return &view_; return &view_;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment