Commit 72ea2a86 authored by Dominik Charousset's avatar Dominik Charousset

Use custom inspect overloads with high priority

parent 7f9eb366
...@@ -590,6 +590,9 @@ struct is_same_ish ...@@ -590,6 +590,9 @@ struct is_same_ish
template <class> template <class>
struct always_false : std::false_type {}; struct always_false : std::false_type {};
template <class T>
constexpr bool always_false_v = always_false<T>::value;
/// Utility trait for removing const inside a `map<K, V>::value_type`. /// Utility trait for removing const inside a `map<K, V>::value_type`.
template <class T> template <class T>
struct deconst_kvp { struct deconst_kvp {
......
...@@ -97,6 +97,12 @@ private: ...@@ -97,6 +97,12 @@ private:
using squashed_type = detail::squashed_int_t<T>; using squashed_type = detail::squashed_int_t<T>;
auto squashed_x = static_cast<squashed_type>(x); auto squashed_x = static_cast<squashed_type>(x);
CAF_READ_INSPECTOR_TRY(dref.apply(squashed_x)) CAF_READ_INSPECTOR_TRY(dref.apply(squashed_x))
} else if constexpr (detail::is_inspectable<Subtype, T>::value) {
using caf::detail::inspect;
// We require that the implementation for `inspect` does not modify its
// arguments when passing a reading inspector.
auto& mutable_x = const_cast<T&>(x);
CAF_READ_INSPECTOR_TRY(inspect(dref, mutable_x));
} else if constexpr (detail::can_apply_v<Subtype, decltype(x)>) { } else if constexpr (detail::can_apply_v<Subtype, decltype(x)>) {
CAF_READ_INSPECTOR_TRY(dref.apply(x)) CAF_READ_INSPECTOR_TRY(dref.apply(x))
} else if constexpr (std::is_array<T>::value) { } else if constexpr (std::is_array<T>::value) {
...@@ -118,12 +124,8 @@ private: ...@@ -118,12 +124,8 @@ private:
} }
CAF_READ_INSPECTOR_TRY(dref.end_sequence()) CAF_READ_INSPECTOR_TRY(dref.end_sequence())
} else { } else {
static_assert(detail::is_inspectable<Subtype, T>::value); static_assert(detail::always_false_v<T>,
using caf::detail::inspect; "T is neither inspectable nor default-applicable");
// We require that the implementation for `inspect` does not modify its
// arguments when passing a reading inspector.
auto& mutable_x = const_cast<T&>(x);
CAF_READ_INSPECTOR_TRY(inspect(dref, mutable_x));
} }
return true; return true;
} }
......
...@@ -96,6 +96,9 @@ private: ...@@ -96,6 +96,9 @@ private:
using squashed_type = detail::squashed_int_t<T>; using squashed_type = detail::squashed_int_t<T>;
auto& squashed_x = reinterpret_cast<squashed_type&>(x); auto& squashed_x = reinterpret_cast<squashed_type&>(x);
CAF_WRITE_INSPECTOR_TRY(dref.apply(squashed_x)) CAF_WRITE_INSPECTOR_TRY(dref.apply(squashed_x))
} else if constexpr (detail::is_inspectable<Subtype, T>::value) {
using caf::detail::inspect;
CAF_WRITE_INSPECTOR_TRY(inspect(dref, x));
} else if constexpr (detail::can_apply_v<Subtype, decltype(x)>) { } else if constexpr (detail::can_apply_v<Subtype, decltype(x)>) {
CAF_WRITE_INSPECTOR_TRY(dref.apply(x)) CAF_WRITE_INSPECTOR_TRY(dref.apply(x))
} else if constexpr (std::is_array<T>::value) { } else if constexpr (std::is_array<T>::value) {
...@@ -126,9 +129,8 @@ private: ...@@ -126,9 +129,8 @@ private:
} }
CAF_WRITE_INSPECTOR_TRY(dref.end_sequence()) CAF_WRITE_INSPECTOR_TRY(dref.end_sequence())
} else { } else {
static_assert(detail::is_inspectable<Subtype, T>::value); static_assert(detail::always_false_v<T>,
using caf::detail::inspect; "T is neither inspectable nor default-applicable");
CAF_WRITE_INSPECTOR_TRY(inspect(dref, x));
} }
return true; return true;
} }
......
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