Commit d743e8e3 authored by Marian Triebe's avatar Marian Triebe

Add check for `result` type to `deliver`

This commit adds a `static_assert` to `response_promise::deliver` which
prevents faulty usage of `result<...>` and `deliver`.

closes #592
parent 35405ce6
...@@ -147,7 +147,7 @@ struct is_duration : std::false_type {}; ...@@ -147,7 +147,7 @@ struct is_duration : std::false_type {};
template <class Period, class Rep> template <class Period, class Rep>
struct is_duration<std::chrono::duration<Period, Rep>> : std::true_type {}; struct is_duration<std::chrono::duration<Period, Rep>> : std::true_type {};
/// Checks wheter `T` is considered a builtin type. /// Checks whether `T` is considered a builtin type.
/// ///
/// Builtin types are: (1) all arithmetic types (including time types), (2) /// Builtin types are: (1) all arithmetic types (including time types), (2)
/// string types from the STL, and (3) built-in types such as `actor_ptr`. /// string types from the STL, and (3) built-in types such as `actor_ptr`.
...@@ -161,8 +161,8 @@ struct is_builtin { ...@@ -161,8 +161,8 @@ struct is_builtin {
node_id>::value; node_id>::value;
}; };
/// Chekcs wheter `T` is primitive, i.e., either an arithmetic /// Checks whether `T` is primitive, i.e., either an arithmetic type or
/// type or convertible to one of STL's string types. /// convertible to one of STL's string types.
template <class T> template <class T>
struct is_primitive { struct is_primitive {
static constexpr bool value = std::is_arithmetic<T>::value static constexpr bool value = std::is_arithmetic<T>::value
...@@ -172,7 +172,7 @@ struct is_primitive { ...@@ -172,7 +172,7 @@ struct is_primitive {
|| std::is_convertible<T, atom_value>::value; || std::is_convertible<T, atom_value>::value;
}; };
/// Chekcs wheter `T1` is comparable with `T2`. /// Checks whether `T1` is comparable with `T2`.
template <class T1, typename T2> template <class T1, typename T2>
class is_comparable { class is_comparable {
// SFINAE: If you pass a "bool*" as third argument, then // SFINAE: If you pass a "bool*" as third argument, then
...@@ -607,6 +607,13 @@ constexpr bool can_insert_elements() { ...@@ -607,6 +607,13 @@ constexpr bool can_insert_elements() {
return can_insert_elements_impl<T>(static_cast<T*>(nullptr)); return can_insert_elements_impl<T>(static_cast<T*>(nullptr));
} }
/// Checks whether `Tpl` is a specialization of `T` or not.
template <template <class...> class Tpl, class T>
struct is_specialization : std::false_type { };
template <template <class...> class T, class... Ts>
struct is_specialization<T, T<Ts...>> : std::true_type { };
} // namespace detail } // namespace detail
} // namespace caf } // namespace caf
......
...@@ -57,6 +57,11 @@ public: ...@@ -57,6 +57,11 @@ public:
response_promise response_promise
>::type >::type
deliver(T&&x, Ts&&... xs) { deliver(T&&x, Ts&&... xs) {
static_assert(!detail::is_specialization<result, T>::value
&& !detail::disjunction<
detail::is_specialization<result, Ts>::value...
>::value,
"it is not possible to deliver objects of type result<...>");
return deliver_impl(make_message(std::forward<T>(x), return deliver_impl(make_message(std::forward<T>(x),
std::forward<Ts>(xs)...)); std::forward<Ts>(xs)...));
} }
......
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