Commit 7a3a5880 authored by Shariar Azad Riday's avatar Shariar Azad Riday

Address review feedback and refactor additional calls with $pred<>::value

parent f722e047
...@@ -219,7 +219,7 @@ public: ...@@ -219,7 +219,7 @@ public:
static std::string render(const T& x) { static std::string render(const T& x) {
if constexpr (std::is_same_v<std::nullptr_t, T>) { if constexpr (std::is_same_v<std::nullptr_t, T>) {
return "null"; return "null";
} else if constexpr (std::is_constructible<std::string_view, T>::value) { } else if constexpr (std::is_constructible_v<std::string_view, T>) {
if constexpr (std::is_pointer_v<T>) { if constexpr (std::is_pointer_v<T>) {
if (x == nullptr) if (x == nullptr)
return "null"; return "null";
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
static constexpr bool value = sfinae_type::value; \ static constexpr bool value = sfinae_type::value; \
}; \ }; \
template <class T> \ template <class T> \
constexpr bool has_##name##_member_v = has_##name##_member<T>::value; constexpr bool has_##name##_member_v = has_##name##_member<T>::value
#define CAF_HAS_ALIAS_TRAIT(name) \ #define CAF_HAS_ALIAS_TRAIT(name) \
template <class T> \ template <class T> \
...@@ -175,13 +175,14 @@ class is_comparable { ...@@ -175,13 +175,14 @@ class is_comparable {
using result_type = decltype(cmp_help_fun( using result_type = decltype(cmp_help_fun(
static_cast<T1*>(nullptr), static_cast<T2*>(nullptr), static_cast<T1*>(nullptr), static_cast<T2*>(nullptr),
static_cast<bool*>(nullptr), static_cast<bool*>(nullptr),
std::integral_constant<bool, std::is_arithmetic<T1>::value std::integral_constant<bool, std::is_arithmetic_v<T1>
&& std::is_arithmetic<T2>::value>{})); && std::is_arithmetic_v<T2>>{}));
public: public:
static constexpr bool value = std::is_same_v<bool, result_type>; static constexpr bool value = std::is_same_v<bool, result_type>;
}; };
/// Convenience alias for `is_comparable<T1, T2>::value`.
template <class T1, class T2> template <class T1, class T2>
constexpr bool is_comparable_v = is_comparable<T1, T2>::value; constexpr bool is_comparable_v = is_comparable<T1, T2>::value;
...@@ -465,6 +466,10 @@ struct is_handler_for { ...@@ -465,6 +466,10 @@ struct is_handler_for {
|| std::is_convertible_v<F, std::function<void(const T&)>>; || std::is_convertible_v<F, std::function<void(const T&)>>;
}; };
/// Convenience alias for `is_handler_for<F, T>::value`.
template <class F, class T>
constexpr bool is_handler_for_v = is_handler_for<F, T>::value;
template <class T> template <class T>
struct value_type_of { struct value_type_of {
using type = typename T::value_type; using type = typename T::value_type;
...@@ -482,8 +487,7 @@ template <class T> ...@@ -482,8 +487,7 @@ template <class T>
using is_callable_t = typename std::enable_if<is_callable_v<T>>::type; using is_callable_t = typename std::enable_if<is_callable_v<T>>::type;
template <class F, class T> template <class F, class T>
using is_handler_for_ef = using is_handler_for_ef = typename std::enable_if<is_handler_for_v<F, T>>::type;
typename std::enable_if<is_handler_for<F, T>::value>::type;
template <class T> template <class T>
struct strip_reference_wrapper { struct strip_reference_wrapper {
...@@ -624,10 +628,14 @@ struct all_constructible<type_list<>, type_list<>> : std::true_type {}; ...@@ -624,10 +628,14 @@ struct all_constructible<type_list<>, type_list<>> : std::true_type {};
template <class T, class... Ts, class U, class... Us> template <class T, class... Ts, class U, class... Us>
struct all_constructible<type_list<T, Ts...>, type_list<U, Us...>> { struct all_constructible<type_list<T, Ts...>, type_list<U, Us...>> {
static constexpr bool value static constexpr bool value
= std::is_constructible<T, U>::value = std::is_constructible_v<T, U>
&& all_constructible<type_list<Ts...>, type_list<Us...>>::value; && all_constructible_v<type_list<Ts...>, type_list<Us...>>;
}; };
/// Convenience alias for `all_constructible<Ts, Us>::value`.
template <class Ts, class Us>
constexpr bool all_constructible_v = all_constructible<Ts, Us>::value;
/// Checks whether T behaves like `std::map`. /// Checks whether T behaves like `std::map`.
template <class T> template <class T>
struct is_map_like { struct is_map_like {
...@@ -986,6 +994,11 @@ public: ...@@ -986,6 +994,11 @@ public:
static constexpr bool value = sfinae_result::value; static constexpr bool value = sfinae_result::value;
}; };
/// Convenience alias for `accepts_opaque_value<Inspector, T>::value`.
template <class Inspector, class T>
constexpr bool accepts_opaque_value_v
= accepts_opaque_value<Inspector, T>::value;
/// Checks whether `T` is primitive, i.e., either an arithmetic type or /// Checks whether `T` is primitive, i.e., either an arithmetic type or
/// convertible to one of STL's string types. /// convertible to one of STL's string types.
template <class T, bool IsLoading> template <class T, bool IsLoading>
......
...@@ -126,13 +126,13 @@ bool load(Inspector& f, T& x, inspector_access_type::list) { ...@@ -126,13 +126,13 @@ bool load(Inspector& f, T& x, inspector_access_type::list) {
} }
template <class Inspector, class T> template <class Inspector, class T>
std::enable_if_t<accepts_opaque_value<Inspector, T>::value, bool> std::enable_if_t<accepts_opaque_value_v<Inspector, T>, bool>
load(Inspector& f, T& x, inspector_access_type::none) { load(Inspector& f, T& x, inspector_access_type::none) {
return f.opaque_value(x); return f.opaque_value(x);
} }
template <class Inspector, class T> template <class Inspector, class T>
std::enable_if_t<!accepts_opaque_value<Inspector, T>::value, bool> std::enable_if_t<!accepts_opaque_value_v<Inspector, T>, bool>
load(Inspector&, T&, inspector_access_type::none) { load(Inspector&, T&, inspector_access_type::none) {
static_assert( static_assert(
detail::assertion_failed_v<T>, detail::assertion_failed_v<T>,
...@@ -219,13 +219,13 @@ bool save(Inspector& f, T& x, inspector_access_type::list) { ...@@ -219,13 +219,13 @@ bool save(Inspector& f, T& x, inspector_access_type::list) {
} }
template <class Inspector, class T> template <class Inspector, class T>
std::enable_if_t<accepts_opaque_value<Inspector, T>::value, bool> std::enable_if_t<accepts_opaque_value_v<Inspector, T>, bool>
save(Inspector& f, T& x, inspector_access_type::none) { save(Inspector& f, T& x, inspector_access_type::none) {
return f.opaque_value(x); return f.opaque_value(x);
} }
template <class Inspector, class T> template <class Inspector, class T>
std::enable_if_t<!accepts_opaque_value<Inspector, T>::value, bool> std::enable_if_t<!accepts_opaque_value_v<Inspector, T>, bool>
save(Inspector&, T&, inspector_access_type::none) { save(Inspector&, T&, inspector_access_type::none) {
static_assert( static_assert(
detail::assertion_failed_v<T>, detail::assertion_failed_v<T>,
......
...@@ -29,8 +29,8 @@ public: ...@@ -29,8 +29,8 @@ public:
using const_reference = const value_type&; using const_reference = const value_type&;
using node_type = using node_type =
typename std::conditional<std::is_const_v<T>, const typename T::node_type, typename std::conditional_t<std::is_const_v<T>, const typename T::node_type,
typename T::node_type>::type; typename T::node_type>;
using node_pointer = node_type*; using node_pointer = node_type*;
......
...@@ -261,14 +261,14 @@ operator!=(const T* lhs, const intrusive_ptr<U>& rhs) { ...@@ -261,14 +261,14 @@ operator!=(const T* lhs, const intrusive_ptr<U>& rhs) {
/// @relates intrusive_ptr /// @relates intrusive_ptr
template <class T, class U> template <class T, class U>
detail::enable_if_t<detail::is_comparable<T*, U*>::value, bool> detail::enable_if_t<detail::is_comparable_v<T*, U*>, bool>
operator==(const intrusive_ptr<T>& x, const intrusive_ptr<U>& y) { operator==(const intrusive_ptr<T>& x, const intrusive_ptr<U>& y) {
return x.get() == y.get(); return x.get() == y.get();
} }
/// @relates intrusive_ptr /// @relates intrusive_ptr
template <class T, class U> template <class T, class U>
detail::enable_if_t<detail::is_comparable<T*, U*>::value, bool> detail::enable_if_t<detail::is_comparable_v<T*, U*>, bool>
operator!=(const intrusive_ptr<T>& x, const intrusive_ptr<U>& y) { operator!=(const intrusive_ptr<T>& x, const intrusive_ptr<U>& y) {
return x.get() != y.get(); return x.get() != y.get();
} }
......
...@@ -109,7 +109,7 @@ make_mailbox_element(strong_actor_ptr sender, message_id id, ...@@ -109,7 +109,7 @@ make_mailbox_element(strong_actor_ptr sender, message_id id,
/// @relates mailbox_element /// @relates mailbox_element
template <class T, class... Ts> template <class T, class... Ts>
std::enable_if_t<!std::is_same<typename std::decay<T>::type, message>::value std::enable_if_t<!std::is_same_v<typename std::decay<T>::type, message>
|| (sizeof...(Ts) > 0), || (sizeof...(Ts) > 0),
mailbox_element_ptr> mailbox_element_ptr>
make_mailbox_element(strong_actor_ptr sender, message_id id, make_mailbox_element(strong_actor_ptr sender, message_id id,
......
...@@ -46,7 +46,7 @@ public: ...@@ -46,7 +46,7 @@ public:
template <class... Ts> template <class... Ts>
explicit stateful_actor(actor_config& cfg, Ts&&... xs) : super(cfg) { explicit stateful_actor(actor_config& cfg, Ts&&... xs) : super(cfg) {
if constexpr (std::is_constructible<State, Ts&&...>::value) if constexpr (std::is_constructible_v<State, Ts&&...>)
new (&state) State(std::forward<Ts>(xs)...); new (&state) State(std::forward<Ts>(xs)...);
else else
new (&state) State(this, std::forward<Ts>(xs)...); new (&state) State(this, std::forward<Ts>(xs)...);
......
...@@ -75,8 +75,7 @@ public: ...@@ -75,8 +75,7 @@ public:
/// Satisfies the promise by sending a non-error response message. /// Satisfies the promise by sending a non-error response message.
template <class... Us> template <class... Us>
std::enable_if_t<(std::is_constructible<Ts, Us>::value && ...)> std::enable_if_t<(std::is_constructible_v<Ts, Us> && ...)> deliver(Us... xs) {
deliver(Us... xs) {
promise_.deliver(Ts{std::forward<Us>(xs)}...); promise_.deliver(Ts{std::forward<Us>(xs)}...);
} }
......
...@@ -223,7 +223,7 @@ void check_integer_options(std::false_type) { ...@@ -223,7 +223,7 @@ void check_integer_options(std::false_type) {
// only works with an integral types and double // only works with an integral types and double
template <class T> template <class T>
void check_integer_options() { void check_integer_options() {
std::integral_constant<bool, std::is_unsigned<T>::value> tk; std::integral_constant<bool, std::is_unsigned_v<T>> tk;
check_integer_options<T>(tk); check_integer_options<T>(tk);
} }
......
...@@ -231,14 +231,14 @@ private: ...@@ -231,14 +231,14 @@ private:
}; };
CAF_TEST(is_comparable) { CAF_TEST(is_comparable) {
CHECK((is_comparable<double, std::string>::value) == false); CHECK((is_comparable_v<double, std::string>) == false);
CHECK((is_comparable<foo, foo>::value) == false); CHECK((is_comparable_v<foo, foo>) == false);
CHECK((is_comparable<bar, bar>::value) == true); CHECK((is_comparable_v<bar, bar>) == true);
CHECK((is_comparable<double, bar>::value) == false); CHECK((is_comparable_v<double, bar>) == false);
CHECK((is_comparable<bar, double>::value) == false); CHECK((is_comparable_v<bar, double>) == false);
CHECK((is_comparable<baz, baz>::value) == true); CHECK((is_comparable_v<baz, baz>) == true);
CHECK((is_comparable<double, baz>::value) == false); CHECK((is_comparable_v<double, baz>) == false);
CHECK((is_comparable<baz, double>::value) == false); CHECK((is_comparable_v<baz, double>) == false);
CHECK((is_comparable<std::string, baz>::value) == false); CHECK((is_comparable_v<std::string, baz>) == false);
CHECK((is_comparable<baz, std::string>::value) == false); CHECK((is_comparable_v<baz, std::string>) == false);
} }
...@@ -66,12 +66,12 @@ struct compare_visitor { ...@@ -66,12 +66,12 @@ struct compare_visitor {
struct equality_operator { struct equality_operator {
static constexpr bool default_value = false; static constexpr bool default_value = false;
template <class T, class U, template <
detail::enable_if_t<((std::is_floating_point_v<T> class T, class U,
&& std::is_convertible_v<U, double>) detail::enable_if_t<
|| (std::is_floating_point<U>::value ((std::is_floating_point_v<T> && std::is_convertible_v<U, double>)
&& std::is_convertible_v<T, double>) ) || (std::is_floating_point_v<U> && std::is_convertible_v<T, double>) )
&& detail::is_comparable<T, U>::value, && detail::is_comparable_v<T, U>,
int> int>
= 0> = 0>
bool operator()(const T& t, const U& u) const { bool operator()(const T& t, const U& u) const {
...@@ -82,21 +82,20 @@ struct equality_operator { ...@@ -82,21 +82,20 @@ struct equality_operator {
return dif <= max * 1e-5l; return dif <= max * 1e-5l;
} }
template <class T, class U, template <
detail::enable_if_t<!((std::is_floating_point_v<T> class T, class U,
&& std::is_convertible_v<U, double>) detail::enable_if_t<
|| (std::is_floating_point<U>::value !((std::is_floating_point_v<T> && std::is_convertible_v<U, double>)
&& std::is_convertible_v<T, double>) ) || (std::is_floating_point_v<U> && std::is_convertible_v<T, double>) )
&& detail::is_comparable<T, U>::value, && detail::is_comparable_v<T, U>,
int> int>
= 0> = 0>
bool operator()(const T& x, const U& y) const { bool operator()(const T& x, const U& y) const {
return x == y; return x == y;
} }
template < template <class T, class U,
class T, class U, typename std::enable_if<!detail::is_comparable_v<T, U>>::type = 0>
typename std::enable_if<!detail::is_comparable<T, U>::value, int>::type = 0>
bool operator()(const T&, const U&) const { bool operator()(const T&, const U&) const {
return default_value; return default_value;
} }
...@@ -108,7 +107,7 @@ struct inequality_operator { ...@@ -108,7 +107,7 @@ struct inequality_operator {
template <class T, class U, template <class T, class U,
typename std::enable_if<(std::is_floating_point_v<T> typename std::enable_if<(std::is_floating_point_v<T>
|| std::is_floating_point<U>::value) || std::is_floating_point<U>::value)
&& detail::is_comparable<T, U>::value, && detail::is_comparable_v<T, U>,
int>::type int>::type
= 0> = 0>
bool operator()(const T& x, const U& y) const { bool operator()(const T& x, const U& y) const {
...@@ -118,17 +117,16 @@ struct inequality_operator { ...@@ -118,17 +117,16 @@ struct inequality_operator {
template <class T, class U, template <class T, class U,
typename std::enable_if<!std::is_floating_point_v<T> typename std::enable_if<!std::is_floating_point_v<T>
&& !std::is_floating_point<U>::value && !std::is_floating_point_v<U>
&& detail::is_comparable<T, U>::value, && detail::is_comparable_v<T, U>,
int>::type int>::type
= 0> = 0>
bool operator()(const T& x, const U& y) const { bool operator()(const T& x, const U& y) const {
return x != y; return x != y;
} }
template < template <class T, class U,
class T, class U, typename std::enable_if<!detail::is_comparable_v<T, U>>::type = 0>
typename std::enable_if<!detail::is_comparable<T, U>::value, int>::type = 0>
bool operator()(const T&, const U&) const { bool operator()(const T&, const U&) const {
return default_value; return default_value;
} }
......
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