Commit 721ee285 authored by Dominik Charousset's avatar Dominik Charousset

Fix initialization of typed handles from this

parent 5ca71fab
...@@ -24,11 +24,40 @@ ...@@ -24,11 +24,40 @@
#include <type_traits> #include <type_traits>
#include "caf/fwd.hpp" #include "caf/fwd.hpp"
#include "caf/actor_marker.hpp"
#include "caf/detail/type_list.hpp"
#include "caf/detail/type_traits.hpp" #include "caf/detail/type_traits.hpp"
namespace caf { namespace caf {
namespace detail { namespace detail {
template <class T,
bool IsDyn = std::is_base_of<dynamically_typed_actor_base, T>::value,
bool IsStat = std::is_base_of<statically_typed_actor_base, T>::value>
struct implicit_actor_conversions {
using type = T;
};
template <class T>
struct implicit_actor_conversions<T, true, false> {
using type = actor;
};
template <class T>
struct implicit_actor_conversions<T, false, true> {
using type =
typename detail::tl_apply<
typename T::signatures,
typed_actor
>::type;
};
template <>
struct implicit_actor_conversions<actor_control_block, false, false> {
using type = strong_actor_ptr;
};
template <class T> template <class T>
struct implicit_conversions { struct implicit_conversions {
using type = using type =
...@@ -40,14 +69,7 @@ struct implicit_conversions { ...@@ -40,14 +69,7 @@ struct implicit_conversions {
}; };
template <class T> template <class T>
struct implicit_conversions<T*> { struct implicit_conversions<T*> : implicit_actor_conversions<T> {};
using type =
typename std::conditional<
std::is_base_of<abstract_actor, T>::value,
actor,
T*
>::type;
};
template <> template <>
struct implicit_conversions<char*> { struct implicit_conversions<char*> {
......
...@@ -139,17 +139,21 @@ class typed_actor : detail::comparable<typed_actor<Sigs...>>, ...@@ -139,17 +139,21 @@ class typed_actor : detail::comparable<typed_actor<Sigs...>>,
signatures, signatures,
detail::type_list<Ts...> detail::type_list<Ts...>
>::value, >::value,
"Cannot assign invalid handle"); "Cannot assign incompatible handle");
} }
// allow `handle_type{this}` for typed actors // allow `handle_type{this}` for typed actors
template <class... Ts> template <class T>
typed_actor(typed_actor<Ts...>* ptr) : ptr_(ptr->ctrl()) { typed_actor(T* ptr,
typename std::enable_if<
std::is_base_of<statically_typed_actor_base, T>::value
>::type* = 0)
: ptr_(ptr->ctrl()) {
static_assert(detail::tl_subset_of< static_assert(detail::tl_subset_of<
signatures, signatures,
detail::type_list<Ts...> typename T::signatures
>::value, >::value,
"Cannot assign invalid handle"); "Cannot assign T* to incompatible handle type");
CAF_ASSERT(ptr != nullptr); CAF_ASSERT(ptr != nullptr);
} }
...@@ -159,7 +163,7 @@ class typed_actor : detail::comparable<typed_actor<Sigs...>>, ...@@ -159,7 +163,7 @@ class typed_actor : detail::comparable<typed_actor<Sigs...>>,
signatures, signatures,
detail::type_list<Ts...> detail::type_list<Ts...>
>::value, >::value,
"Cannot assign invalid handle"); "Cannot assign incompatible handle");
ptr_ = other.ptr_; ptr_ = other.ptr_;
return *this; return *this;
} }
......
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