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