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

Fix initialization of typed handles from this

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