Commit f722e047 authored by Shariar Azad Riday's avatar Shariar Azad Riday

Add new convenience alias and refactor calls to pred<>::value

Alias has been added for $pred<T>::value in is_type_list, tl_size, has_##name_##member,
has_to_string, is_callable and is_handle
parent 1bdc08c6
......@@ -48,6 +48,10 @@ struct is_weak_ptr {
static constexpr bool value = T::has_weak_ptr_semantics;
};
/// Convenience alias for `is_weak_ptr_v`.
template <class T>
constexpr bool is_weak_ptr_v = is_weak_ptr<T>::value;
template <class T>
struct is_weak_ptr<T*> : std::false_type {};
......@@ -149,10 +153,10 @@ T actor_cast(U&& what) {
typename std::remove_const<typename std::remove_reference<U>::type>::type;
// query traits for T
constexpr bool to_raw = std::is_pointer_v<T>;
constexpr bool to_weak = is_weak_ptr<T>::value;
constexpr bool to_weak = is_weak_ptr_v<T>;
// query traits for U
constexpr bool from_raw = std::is_pointer_v<from_type>;
constexpr bool from_weak = is_weak_ptr<from_type>::value;
constexpr bool from_weak = is_weak_ptr_v<from_type>;
// calculate x and y
constexpr int x = to_raw ? 0 : (to_weak ? 2 : 1);
constexpr int y = from_raw ? 0 : (from_weak ? 3 : 6);
......
......@@ -446,7 +446,7 @@ public:
/// with the arguments stored in `args`.
/// @experimental
template <class Handle,
class E = typename std::enable_if<is_handle<Handle>::value>::type>
class E = typename std::enable_if<is_handle_v<Handle>>::type>
expected<Handle>
spawn(const std::string& name, message args, execution_unit* ctx = nullptr,
bool check_interface = true, const mpi* expected_ifs = nullptr) {
......
......@@ -174,7 +174,7 @@ public:
bool value(uint64_t& x) noexcept;
template <class T>
std::enable_if_t<std::is_integral<T>::value, bool> value(T& x) noexcept {
std::enable_if_t<std::is_integral_v<T>, bool> value(T& x) noexcept {
auto tmp = detail::squashed_int_t<T>{0};
if (value(tmp)) {
x = static_cast<T>(tmp);
......
......@@ -157,7 +157,7 @@ public:
bool value(uint64_t x);
template <class T>
std::enable_if_t<std::is_integral<T>::value, bool> value(T x) {
std::enable_if_t<std::is_integral_v<T>, bool> value(T x) {
return value(static_cast<detail::squashed_int_t<T>>(x));
}
......
......@@ -312,7 +312,7 @@ public:
filtered tk;
behavior bhvr{apply_moved_args(make_behavior_impl, get_indices(tk), tup)};
using tail_indices =
typename il_range<tl_size<filtered>::value, sizeof...(Ts)>::type;
typename il_range<tl_size_v<filtered>, sizeof...(Ts)>::type;
make_blocking_behavior_t factory;
auto fun = apply_moved_args_prefixed(factory, tail_indices{}, tup, &bhvr);
receive_impl(rcc, mid, fun);
......
......@@ -8,7 +8,7 @@
namespace caf {
template <class IntegerType,
class = std::enable_if_t<std::is_integral<IntegerType>::value>>
class = std::enable_if_t<std::is_integral_v<IntegerType>>>
[[deprecated("use std::to_integer instead")]] constexpr IntegerType
to_integer(std::byte x) noexcept {
return static_cast<IntegerType>(x);
......
......@@ -297,7 +297,7 @@ private:
} else {
static_assert(detail::is_iterable<T>::value);
using value_type = typename T::value_type;
detail::bool_token<detail::is_pair<value_type>::value> is_map_type;
detail::bool_token<detail::is_pair_v<value_type>> is_map_type;
set_range(x, is_map_type);
}
}
......
......@@ -403,8 +403,8 @@ namespace {
template <class T>
bool pull(config_value_reader& reader, T& x) {
using internal_type = std::conditional_t<std::is_floating_point<T>::value,
config_value::real, T>;
using internal_type
= std::conditional_t<std::is_floating_point_v<T>, config_value::real, T>;
auto assign = [&x](auto& result) {
if constexpr (std::is_floating_point<T>::value) {
x = static_cast<T>(result);
......
......@@ -158,7 +158,7 @@ public:
/// @copydoc value
template <class T>
std::enable_if_t<std::is_integral<T>::value, bool> value(T& x) noexcept {
std::enable_if_t<std::is_integral_v<T>, bool> value(T& x) noexcept {
auto tmp = detail::squashed_int_t<T>{0};
if (value(tmp)) {
x = static_cast<T>(tmp);
......
......@@ -72,7 +72,7 @@ CAF_CORE_EXPORT void parse(string_parser_state& ps, uint64_t& x);
// -- non-fixed size integer types ---------------------------------------------
template <class T>
detail::enable_if_t<std::is_integral<T>::value>
detail::enable_if_t<std::is_integral_v<T>>
parse(string_parser_state& ps, T& x) {
using squashed_type = squashed_int_t<T>;
return parse(ps, reinterpret_cast<squashed_type&>(x));
......
......@@ -128,7 +128,7 @@ void print(Buffer& buf, bool x) {
}
template <class Buffer, class T>
std::enable_if_t<std::is_integral<T>::value> print(Buffer& buf, T x) {
std::enable_if_t<std::is_integral_v<T>> print(Buffer& buf, T x) {
// An integer can at most have 20 digits (UINT64_MAX).
char stack_buffer[24];
char* p = stack_buffer;
......@@ -172,7 +172,7 @@ std::enable_if_t<std::is_integral<T>::value> print(Buffer& buf, T x) {
}
template <class Buffer, class T>
std::enable_if_t<std::is_floating_point<T>::value> print(Buffer& buf, T x) {
std::enable_if_t<std::is_floating_point_v<T>> print(Buffer& buf, T x) {
// TODO: Check whether to_chars is available on supported compilers and
// re-implement using the new API as soon as possible.
auto str = std::to_string(x);
......
......@@ -42,7 +42,7 @@ struct int_types_by_size<8> {
template <class T>
struct squashed_int {
using tpair = int_types_by_size<sizeof(T)>;
using type = std::conditional_t<std::is_signed<T>::value, //
using type = std::conditional_t<std::is_signed_v<T>, //
typename tpair::signed_type, //
typename tpair::unsigned_type>;
};
......
......@@ -90,7 +90,7 @@ public:
bool value(bool x);
template <class Integral>
std::enable_if_t<std::is_integral<Integral>::value, bool> value(Integral x) {
std::enable_if_t<std::is_integral_v<Integral>, bool> value(Integral x) {
if constexpr (std::is_signed<Integral>::value)
return int_value(static_cast<int64_t>(x));
else
......@@ -151,9 +151,8 @@ public:
}
template <class T>
std::enable_if_t<has_to_string<T>::value
&& !std::is_convertible_v<T, std::string_view>,
bool>
std::enable_if_t<
has_to_string_v<T> && !std::is_convertible_v<T, std::string_view>, bool>
builtin_inspect(const T& x) {
auto str = to_string(x);
if constexpr (std::is_convertible<decltype(str), const char*>::value) {
......
......@@ -45,9 +45,9 @@ struct is_type_list<type_list<Ts...>> {
static constexpr bool value = true;
};
// Uncomment after having switched to C++14
// template <class T>
// inline constexpr bool is_type_list_v = is_type_list<T>::value;
/// Convenience alias for `is_type_list<T>::value`.
template <class T>
inline constexpr bool is_type_list_v = is_type_list<T>::value;
// T head(type_list)
......@@ -101,9 +101,9 @@ struct tl_size<type_list<Ts...>> {
template <class... Ts>
constexpr size_t tl_size<type_list<Ts...>>::value;
// Uncomment after having switched to C++14
// template <class List>
// inline constexpr size_t tl_size_v = tl_size<List>::value;
/// Convenience alias for `tl_size<List>::value`.
template <class List>
inline constexpr size_t tl_size_v = tl_size<List>::value;
// T back(type_list)
......
......@@ -34,7 +34,9 @@
\
public: \
static constexpr bool value = sfinae_type::value; \
}
}; \
template <class T> \
constexpr bool has_##name##_member_v = has_##name##_member<T>::value;
#define CAF_HAS_ALIAS_TRAIT(name) \
template <class T> \
......@@ -91,6 +93,11 @@ public:
static constexpr bool value = std::is_convertible_v<result, std::string>;
};
/// Convenience alias for `has_to_string<T>::value`.
/// @relates has_to_string
template <class T>
constexpr bool has_to_string_v = has_to_string<T>::value;
template <bool X>
using bool_token = std::integral_constant<bool, X>;
......@@ -369,6 +376,11 @@ public:
static constexpr bool value = std::is_same_v<bool, result_type>;
};
/// Convenience alias for `is_callable<T>::value`.
/// @relates is_callable
template <class T>
constexpr bool is_callable_v = is_callable<T>::value;
/// Checks whether `F` is callable with arguments of types `Ts...`.
template <class F, class... Ts>
struct is_callable_with {
......@@ -467,7 +479,7 @@ template <class T>
using value_type_of_t = typename value_type_of<T>::type;
template <class T>
using is_callable_t = typename std::enable_if<is_callable<T>::value>::type;
using is_callable_t = typename std::enable_if<is_callable_v<T>>::type;
template <class F, class T>
using is_handler_for_ef =
......
......@@ -105,7 +105,7 @@ public:
}
template <class Integral>
std::enable_if_t<std::is_integral<Integral>::value, bool>
std::enable_if_t<std::is_integral_v<Integral>, bool>
value(Integral x) noexcept {
auto begin = reinterpret_cast<const uint8_t*>(&x);
append(begin, begin + sizeof(Integral));
......
......@@ -100,7 +100,7 @@ public:
}
template <class Integral>
std::enable_if_t<std::is_integral<Integral>::value, bool>
std::enable_if_t<std::is_integral_v<Integral>, bool>
value(Integral x) noexcept {
auto begin = reinterpret_cast<const uint8_t*>(&x);
append(begin, begin + sizeof(Integral));
......
......@@ -137,4 +137,8 @@ struct is_handle<strong_actor_ptr> : std::true_type {};
template <class... Ts>
struct is_handle<typed_actor<Ts...>> : std::true_type {};
/// Convenience alias for `is_handle<T>::value`.
template <class T>
inline constexpr bool is_handle_v = is_handle<T>::value;
} // namespace caf
......@@ -28,9 +28,9 @@ public:
using const_reference = const value_type&;
using node_type = typename std::conditional<std::is_const<T>::value,
const typename T::node_type,
typename T::node_type>::type;
using node_type =
typename std::conditional<std::is_const_v<T>, const typename T::node_type,
typename T::node_type>::type;
using node_pointer = node_type*;
......
......@@ -88,7 +88,7 @@ public:
template <class T>
bool tuple(T& xs) {
return tuple(xs, std::make_index_sequence<std::tuple_size<T>::value>{});
return tuple(xs, std::make_index_sequence<std::tuple_size_v<T>>{});
}
template <class T, size_t N>
......
......@@ -230,7 +230,7 @@ message make_message_from_tuple(Tuple&& xs, std::index_sequence<Is...>) {
template <class Tuple>
message make_message_from_tuple(Tuple&& xs) {
using tuple_type = std::decay_t<Tuple>;
std::make_index_sequence<std::tuple_size<tuple_type>::value> seq;
std::make_index_sequence<std::tuple_size_v<tuple_type>> seq;
return make_message_from_tuple(std::forward<Tuple>(xs), seq);
}
......
......@@ -81,7 +81,7 @@ public:
template <class T>
bool tuple(const T& xs) {
return tuple(xs, std::make_index_sequence<std::tuple_size<T>::value>{});
return tuple(xs, std::make_index_sequence<std::tuple_size_v<T>>{});
}
template <class T, size_t N>
......
......@@ -134,7 +134,7 @@ public:
/// @copydoc value
template <class T>
std::enable_if_t<std::is_integral<T>::value, bool> value(T x) {
std::enable_if_t<std::is_integral_v<T>, bool> value(T x) {
return value(static_cast<detail::squashed_int_t<T>>(x));
}
......
......@@ -28,7 +28,7 @@ public:
/// on whether `State::make_behavior()` exists.
template <class State, class Base>
using stateful_actor_base_t
= std::conditional_t<has_make_behavior_member<State>::value,
= std::conditional_t<has_make_behavior_member_v<State>,
stateful_actor_base<State, Base>, Base>;
} // namespace caf::detail
......
......@@ -31,13 +31,12 @@ struct is_string_like {
const U* x,
// check if `x->data()` returns const char*
std::enable_if_t<
std::is_same<const char*, decltype(x->data())>::value>* = nullptr,
std::is_same_v<const char*, decltype(x->data())>>* = nullptr,
// check if `x->size()` returns an integer
std::enable_if_t<std::is_integral<decltype(x->size())>::value>* = nullptr,
std::enable_if_t<std::is_integral_v<decltype(x->size())>>* = nullptr,
// check if `x->find('?', 0)` is well-formed and returns an integer
// (distinguishes vectors from strings)
std::enable_if_t<
std::is_integral<decltype(x->find('?', 0))>::value>* = nullptr);
std::enable_if_t<std::is_integral_v<decltype(x->find('?', 0))>>* = nullptr);
// SFINAE fallback.
static void sfinae(void*);
......
......@@ -58,7 +58,7 @@ template <class... Ts>
void append(prometheus::char_buffer&, double, Ts&&...);
template <class T, class... Ts>
std::enable_if_t<std::is_integral<T>::value>
std::enable_if_t<std::is_integral_v<T>>
append(prometheus::char_buffer& buf, T val, Ts&&... xs);
template <class... Ts>
......@@ -120,7 +120,7 @@ void append(prometheus::char_buffer& buf, double val, Ts&&... xs) {
}
template <class T, class... Ts>
std::enable_if_t<std::is_integral<T>::value>
std::enable_if_t<std::is_integral_v<T>>
append(prometheus::char_buffer& buf, T val, Ts&&... xs) {
append(buf, std::to_string(val));
append(buf, std::forward<Ts>(xs)...);
......
......@@ -105,13 +105,12 @@ struct range_parser {
};
template <class T>
typename std::enable_if<std::is_integral<T>::value, res_t>::type res(T x) {
typename std::enable_if<std::is_integral_v<T>, res_t>::type res(T x) {
return {static_cast<int64_t>(x)};
}
template <class T>
typename std::enable_if<std::is_floating_point<T>::value, res_t>::type
res(T x) {
typename std::enable_if<std::is_floating_point_v<T>, res_t>::type res(T x) {
return {static_cast<double>(x)};
}
......
......@@ -72,13 +72,12 @@ struct fixture {
};
template <class T>
typename std::enable_if<std::is_integral<T>::value, res_t>::type res(T x) {
typename std::enable_if<std::is_integral_v<T>, res_t>::type res(T x) {
return res_t{static_cast<int64_t>(x)};
}
template <class T>
typename std::enable_if<std::is_floating_point<T>::value, res_t>::type
res(T x) {
typename std::enable_if<std::is_floating_point_v<T>, res_t>::type res(T x) {
return res_t{static_cast<double>(x)};
}
......
......@@ -67,7 +67,7 @@ struct equality_operator {
static constexpr bool default_value = false;
template <class T, class U,
detail::enable_if_t<((std::is_floating_point<T>::value
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>) )
......@@ -83,7 +83,7 @@ struct equality_operator {
}
template <class T, class U,
detail::enable_if_t<!((std::is_floating_point<T>::value
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>) )
......@@ -106,7 +106,7 @@ struct inequality_operator {
static constexpr bool default_value = true;
template <class T, class U,
typename std::enable_if<(std::is_floating_point<T>::value
typename std::enable_if<(std::is_floating_point_v<T>
|| std::is_floating_point<U>::value)
&& detail::is_comparable<T, U>::value,
int>::type
......@@ -117,7 +117,7 @@ struct inequality_operator {
}
template <class T, class U,
typename std::enable_if<!std::is_floating_point<T>::value
typename std::enable_if<!std::is_floating_point_v<T>
&& !std::is_floating_point<U>::value
&& detail::is_comparable<T, U>::value,
int>::type
......
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