Merge pull request #52898 from ucasfl/concept

Use concepts to replace more std::enable_if_t
This commit is contained in:
Alexey Milovidov 2023-08-07 16:13:29 +03:00 committed by GitHub
commit 2c8eb7fa08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 29 deletions

View File

@ -18,7 +18,8 @@
namespace
{
template <typename T, typename = std::enable_if_t<std::is_fundamental_v<std::decay_t<T>>>>
template <typename T>
requires std::is_fundamental_v<std::decay_t<T>>
void updateHash(SipHash & hash, const T & value)
{
hash.update(value);

View File

@ -81,9 +81,9 @@ public:
}
/// Message must be a compile-time constant
template<typename T, typename = std::enable_if_t<std::is_convertible_v<T, String>>>
Exception(int code, T && message)
: Exception(message, code)
template <typename T>
requires std::is_convertible_v<T, String>
Exception(int code, T && message) : Exception(message, code)
{
capture_thread_frame_pointers = thread_frame_pointers;
message_format_string = tryGetStaticFormatString(message);

View File

@ -3,8 +3,8 @@
#include <base/defines.h>
#include <base/sort.h>
#include <vector>
#include <utility>
#include <vector>
namespace DB
@ -119,7 +119,8 @@ public:
return true;
}
template <typename TValue = Value, std::enable_if_t<!std::is_same_v<TValue, IntervalTreeVoidValue>, bool> = true, typename... Args>
template <typename TValue = Value, bool = true, typename... Args>
requires(!std::is_same_v<TValue, IntervalTreeVoidValue>)
ALWAYS_INLINE bool emplace(Interval interval, Args &&... args)
{
assert(!tree_is_built);

View File

@ -9,7 +9,8 @@ namespace DB
class NetException : public Exception
{
public:
template<typename T, typename = std::enable_if_t<std::is_convertible_v<T, String>>>
template <typename T>
requires std::is_convertible_v<T, String>
NetException(int code, T && message) : Exception(std::forward<T>(message), code)
{
message_format_string = tryGetStaticFormatString(message);

View File

@ -12,9 +12,9 @@ struct MultiEnum
MultiEnum() = default;
template <typename ... EnumValues, typename = std::enable_if_t<std::conjunction_v<std::is_same<EnumTypeT, EnumValues>...>>>
constexpr explicit MultiEnum(EnumValues ... v)
: MultiEnum((toBitFlag(v) | ... | 0u))
template <typename... EnumValues>
requires std::conjunction_v<std::is_same<EnumTypeT, EnumValues>...>
constexpr explicit MultiEnum(EnumValues... v) : MultiEnum((toBitFlag(v) | ... | 0u))
{}
template <typename ValueType>

View File

@ -189,10 +189,10 @@ void SerializationNullable::serializeBinary(const IColumn & column, size_t row_n
/// Deserialize value into ColumnNullable.
/// We need to insert both to nested column and to null byte map, or, in case of exception, to not insert at all.
template <typename ReturnType = void, typename CheckForNull, typename DeserializeNested, typename std::enable_if_t<std::is_same_v<ReturnType, void>, ReturnType>* = nullptr>
static ReturnType safeDeserialize(
IColumn & column, const ISerialization &,
CheckForNull && check_for_null, DeserializeNested && deserialize_nested)
template <typename ReturnType = void, typename CheckForNull, typename DeserializeNested, ReturnType * = nullptr>
requires std::same_as<ReturnType, void>
static ReturnType
safeDeserialize(IColumn & column, const ISerialization &, CheckForNull && check_for_null, DeserializeNested && deserialize_nested)
{
ColumnNullable & col = assert_cast<ColumnNullable &>(column);
@ -217,10 +217,10 @@ static ReturnType safeDeserialize(
}
/// Deserialize value into non-nullable column. In case of NULL, insert default value and return false.
template <typename ReturnType = void, typename CheckForNull, typename DeserializeNested, typename std::enable_if_t<std::is_same_v<ReturnType, bool>, ReturnType>* = nullptr>
static ReturnType safeDeserialize(
IColumn & column, const ISerialization &,
CheckForNull && check_for_null, DeserializeNested && deserialize_nested)
template <typename ReturnType = void, typename CheckForNull, typename DeserializeNested, ReturnType * = nullptr>
requires std::same_as<ReturnType, bool>
static ReturnType
safeDeserialize(IColumn & column, const ISerialization &, CheckForNull && check_for_null, DeserializeNested && deserialize_nested)
{
bool insert_default = check_for_null();
if (insert_default)

View File

@ -534,18 +534,15 @@ struct JavaHashImpl
static_cast<uint32_t>(x) ^ static_cast<uint32_t>(static_cast<uint64_t>(x) >> 32));
}
template <class T, typename std::enable_if<std::is_same_v<T, int8_t>
|| std::is_same_v<T, int16_t>
|| std::is_same_v<T, int32_t>, T>::type * = nullptr>
template <class T, T * = nullptr>
requires std::same_as<T, int8_t> || std::same_as<T, int16_t> || std::same_as<T, int32_t>
static ReturnType apply(T x)
{
return x;
}
template <typename T, typename std::enable_if<!std::is_same_v<T, int8_t>
&& !std::is_same_v<T, int16_t>
&& !std::is_same_v<T, int32_t>
&& !std::is_same_v<T, int64_t>, T>::type * = nullptr>
template <class T, T * = nullptr>
requires(!std::same_as<T, int8_t> && !std::same_as<T, int16_t> && !std::same_as<T, int32_t>)
static ReturnType apply(T x)
{
if (std::is_unsigned_v<T>)

View File

@ -88,8 +88,9 @@ public:
}
}
template <typename T, typename ... Args, typename = std::enable_if_t<!std::is_same_v<T, DateTime64>>>
inline auto execute(const T & t, Args && ... args) const
template <typename T, typename... Args>
requires (!std::same_as<T, DateTime64>)
inline auto execute(const T & t, Args &&... args) const
{
return wrapped_transform.execute(t, std::forward<Args>(args)...);
}
@ -128,7 +129,8 @@ public:
}
}
template <typename T, typename ... Args, typename = std::enable_if_t<!std::is_same_v<T, DateTime64>>>
template <typename T, typename ... Args>
requires (!std::same_as<T, DateTime64>)
inline auto executeExtendedResult(const T & t, Args && ... args) const
{
return wrapped_transform.executeExtendedResult(t, std::forward<Args>(args)...);

View File

@ -108,7 +108,8 @@ namespace
});
}
template <typename T, typename = std::enable_if_t<std::is_same_v<T, double> || std::is_same_v<T, QuotaValue>>>
template <typename T>
requires std::same_as<T, double> || std::same_as<T, QuotaValue>
T fieldToNumber(const Field & f)
{
if (f.getType() == Field::Types::String)