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
template <class>
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`.
template <class T>
struct deconst_kvp {
......
......@@ -97,6 +97,12 @@ private:
using squashed_type = detail::squashed_int_t<T>;
auto squashed_x = static_cast<squashed_type>(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)>) {
CAF_READ_INSPECTOR_TRY(dref.apply(x))
} else if constexpr (std::is_array<T>::value) {
......@@ -118,12 +124,8 @@ private:
}
CAF_READ_INSPECTOR_TRY(dref.end_sequence())
} else {
static_assert(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));
static_assert(detail::always_false_v<T>,
"T is neither inspectable nor default-applicable");
}
return true;
}
......
......@@ -96,6 +96,9 @@ private:
using squashed_type = detail::squashed_int_t<T>;
auto& squashed_x = reinterpret_cast<squashed_type&>(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)>) {
CAF_WRITE_INSPECTOR_TRY(dref.apply(x))
} else if constexpr (std::is_array<T>::value) {
......@@ -126,9 +129,8 @@ private:
}
CAF_WRITE_INSPECTOR_TRY(dref.end_sequence())
} else {
static_assert(detail::is_inspectable<Subtype, T>::value);
using caf::detail::inspect;
CAF_WRITE_INSPECTOR_TRY(inspect(dref, x));
static_assert(detail::always_false_v<T>,
"T is neither inspectable nor default-applicable");
}
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