Merge pull request #35347 from rschu1ze/enable-if-to-concepts

Replace a few uses of enable_if for SFINAE by concepts
This commit is contained in:
Maksim Kita 2022-03-17 10:34:08 +01:00 committed by GitHub
commit 4d8c2b2009
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 127 additions and 89 deletions

View File

@ -38,7 +38,8 @@ struct AggregateFunctionWithProperties
AggregateFunctionWithProperties(const AggregateFunctionWithProperties &) = default; AggregateFunctionWithProperties(const AggregateFunctionWithProperties &) = default;
AggregateFunctionWithProperties & operator = (const AggregateFunctionWithProperties &) = default; AggregateFunctionWithProperties & operator = (const AggregateFunctionWithProperties &) = default;
template <typename Creator, std::enable_if_t<!std::is_same_v<Creator, AggregateFunctionWithProperties>> * = nullptr> template <typename Creator>
requires (!std::is_same_v<Creator, AggregateFunctionWithProperties>)
AggregateFunctionWithProperties(Creator creator_, AggregateFunctionProperties properties_ = {}) /// NOLINT AggregateFunctionWithProperties(Creator creator_, AggregateFunctionProperties properties_ = {}) /// NOLINT
: creator(std::forward<Creator>(creator_)), properties(std::move(properties_)) : creator(std::forward<Creator>(creator_)), properties(std::move(properties_))
{ {

View File

@ -883,8 +883,8 @@ public:
return toDayNum(years_lut[year - DATE_LUT_MIN_YEAR]); return toDayNum(years_lut[year - DATE_LUT_MIN_YEAR]);
} }
template <typename Date, template <typename Date>
typename = std::enable_if_t<std::is_same_v<Date, DayNum> || std::is_same_v<Date, ExtendedDayNum>>> requires std::is_same_v<Date, DayNum> || std::is_same_v<Date, ExtendedDayNum>
inline auto toStartOfQuarterInterval(Date d, UInt64 quarters) const inline auto toStartOfQuarterInterval(Date d, UInt64 quarters) const
{ {
if (quarters == 1) if (quarters == 1)
@ -892,8 +892,8 @@ public:
return toStartOfMonthInterval(d, quarters * 3); return toStartOfMonthInterval(d, quarters * 3);
} }
template <typename Date, template <typename Date>
typename = std::enable_if_t<std::is_same_v<Date, DayNum> || std::is_same_v<Date, ExtendedDayNum>>> requires std::is_same_v<Date, DayNum> || std::is_same_v<Date, ExtendedDayNum>
inline auto toStartOfMonthInterval(Date d, UInt64 months) const inline auto toStartOfMonthInterval(Date d, UInt64 months) const
{ {
if (months == 1) if (months == 1)
@ -906,8 +906,8 @@ public:
return toDayNum(years_months_lut[month_total_index / months * months]); return toDayNum(years_months_lut[month_total_index / months * months]);
} }
template <typename Date, template <typename Date>
typename = std::enable_if_t<std::is_same_v<Date, DayNum> || std::is_same_v<Date, ExtendedDayNum>>> requires std::is_same_v<Date, DayNum> || std::is_same_v<Date, ExtendedDayNum>
inline auto toStartOfWeekInterval(Date d, UInt64 weeks) const inline auto toStartOfWeekInterval(Date d, UInt64 weeks) const
{ {
if (weeks == 1) if (weeks == 1)
@ -920,8 +920,8 @@ public:
return ExtendedDayNum(4 + (d - 4) / days * days); return ExtendedDayNum(4 + (d - 4) / days * days);
} }
template <typename Date, template <typename Date>
typename = std::enable_if_t<std::is_same_v<Date, DayNum> || std::is_same_v<Date, ExtendedDayNum>>> requires std::is_same_v<Date, DayNum> || std::is_same_v<Date, ExtendedDayNum>
inline Time toStartOfDayInterval(Date d, UInt64 days) const inline Time toStartOfDayInterval(Date d, UInt64 days) const
{ {
if (days == 1) if (days == 1)
@ -1219,10 +1219,8 @@ public:
/// If resulting month has less deys than source month, then saturation can happen. /// If resulting month has less deys than source month, then saturation can happen.
/// Example: 31 Aug + 1 month = 30 Sep. /// Example: 31 Aug + 1 month = 30 Sep.
template < template <typename DateTime>
typename DateTime, requires std::is_same_v<DateTime, UInt32> || std::is_same_v<DateTime, Int64> || std::is_same_v<DateTime, time_t>
typename
= std::enable_if_t<std::is_same_v<DateTime, UInt32> || std::is_same_v<DateTime, Int64> || std::is_same_v<DateTime, time_t>>>
inline Time NO_SANITIZE_UNDEFINED addMonths(DateTime t, Int64 delta) const inline Time NO_SANITIZE_UNDEFINED addMonths(DateTime t, Int64 delta) const
{ {
const auto result_day = addMonthsIndex(t, delta); const auto result_day = addMonthsIndex(t, delta);
@ -1247,8 +1245,8 @@ public:
return res; return res;
} }
template <typename Date, template <typename Date>
typename = std::enable_if_t<std::is_same_v<Date, DayNum> || std::is_same_v<Date, ExtendedDayNum>>> requires std::is_same_v<Date, DayNum> || std::is_same_v<Date, ExtendedDayNum>
inline auto NO_SANITIZE_UNDEFINED addMonths(Date d, Int64 delta) const inline auto NO_SANITIZE_UNDEFINED addMonths(Date d, Int64 delta) const
{ {
if constexpr (std::is_same_v<Date, DayNum>) if constexpr (std::is_same_v<Date, DayNum>)
@ -1280,10 +1278,8 @@ public:
} }
/// Saturation can occur if 29 Feb is mapped to non-leap year. /// Saturation can occur if 29 Feb is mapped to non-leap year.
template < template <typename DateTime>
typename DateTime, requires std::is_same_v<DateTime, UInt32> || std::is_same_v<DateTime, Int64> || std::is_same_v<DateTime, time_t>
typename
= std::enable_if_t<std::is_same_v<DateTime, UInt32> || std::is_same_v<DateTime, Int64> || std::is_same_v<DateTime, time_t>>>
inline Time addYears(DateTime t, Int64 delta) const inline Time addYears(DateTime t, Int64 delta) const
{ {
auto result_day = addYearsIndex(t, delta); auto result_day = addYearsIndex(t, delta);
@ -1308,8 +1304,8 @@ public:
return res; return res;
} }
template <typename Date, template <typename Date>
typename = std::enable_if_t<std::is_same_v<Date, DayNum> || std::is_same_v<Date, ExtendedDayNum>>> requires std::is_same_v<Date, DayNum> || std::is_same_v<Date, ExtendedDayNum>
inline auto addYears(Date d, Int64 delta) const inline auto addYears(Date d, Int64 delta) const
{ {
if constexpr (std::is_same_v<Date, DayNum>) if constexpr (std::is_same_v<Date, DayNum>)

View File

@ -205,7 +205,8 @@ void rethrowFirstException(const Exceptions & exceptions);
template <typename T> template <typename T>
std::enable_if_t<std::is_pointer_v<T>, T> exception_cast(std::exception_ptr e) requires std::is_pointer_v<T>
T exception_cast(std::exception_ptr e)
{ {
try try
{ {

View File

@ -113,7 +113,8 @@ public:
throw Exception("Cannot convert AggregateFunctionStateData to " + demangle(typeid(T).name()), ErrorCodes::CANNOT_CONVERT_TYPE); throw Exception("Cannot convert AggregateFunctionStateData to " + demangle(typeid(T).name()), ErrorCodes::CANNOT_CONVERT_TYPE);
} }
template <typename U, typename = std::enable_if_t<is_big_int_v<U>> > template <typename U>
requires is_big_int_v<U>
T operator() (const U & x) const T operator() (const U & x) const
{ {
if constexpr (is_decimal<T>) if constexpr (is_decimal<T>)

View File

@ -36,7 +36,8 @@ public:
return x.getValue() != T(0); return x.getValue() != T(0);
} }
template <typename T, typename = std::enable_if_t<is_big_int_v<T>> > template <typename T>
requires is_big_int_v<T>
bool operator() (T & x) const bool operator() (T & x) const
{ {
x += rhs.reinterpret<T>(); x += rhs.reinterpret<T>();

View File

@ -130,6 +130,7 @@ public:
IntervalTree() { nodes.resize(1); } IntervalTree() { nodes.resize(1); }
template <typename TValue = Value, std::enable_if_t<std::is_same_v<TValue, IntervalTreeVoidValue>, bool> = true> template <typename TValue = Value, std::enable_if_t<std::is_same_v<TValue, IntervalTreeVoidValue>, bool> = true>
requires std::is_same_v<Value, IntervalTreeVoidValue>
ALWAYS_INLINE bool emplace(Interval interval) ALWAYS_INLINE bool emplace(Interval interval)
{ {
assert(!tree_is_built); assert(!tree_is_built);

View File

@ -76,7 +76,8 @@ public:
void add(const char * value) { add(std::make_unique<JSONString>(value)); } void add(const char * value) { add(std::make_unique<JSONString>(value)); }
void add(bool value) { add(std::make_unique<JSONBool>(std::move(value))); } void add(bool value) { add(std::make_unique<JSONBool>(std::move(value))); }
template <typename T, std::enable_if_t<std::is_arithmetic_v<T>, bool> = true> template <typename T>
requires std::is_arithmetic_v<T>
void add(T value) { add(std::make_unique<JSONNumber<T>>(value)); } void add(T value) { add(std::make_unique<JSONNumber<T>>(value)); }
void format(const FormatSettings & settings, FormatContext & context) override; void format(const FormatSettings & settings, FormatContext & context) override;
@ -100,7 +101,8 @@ public:
void add(std::string key, std::string_view value) { add(std::move(key), std::make_unique<JSONString>(value)); } void add(std::string key, std::string_view value) { add(std::move(key), std::make_unique<JSONString>(value)); }
void add(std::string key, bool value) { add(std::move(key), std::make_unique<JSONBool>(std::move(value))); } void add(std::string key, bool value) { add(std::move(key), std::make_unique<JSONBool>(std::move(value))); }
template <typename T, std::enable_if_t<std::is_arithmetic_v<T>, bool> = true> template <typename T>
requires std::is_arithmetic_v<T>
void add(std::string key, T value) { add(std::move(key), std::make_unique<JSONNumber<T>>(value)); } void add(std::string key, T value) { add(std::move(key), std::make_unique<JSONNumber<T>>(value)); }
void format(const FormatSettings & settings, FormatContext & context) override; void format(const FormatSettings & settings, FormatContext & context) override;

View File

@ -82,7 +82,8 @@ private:
#endif #endif
public: public:
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
StringSearcher(const CharT * needle_, const size_t needle_size_) StringSearcher(const CharT * needle_, const size_t needle_size_)
: needle{reinterpret_cast<const uint8_t *>(needle_)}, needle_size{needle_size_} : needle{reinterpret_cast<const uint8_t *>(needle_)}, needle_size{needle_size_}
{ {
@ -191,7 +192,8 @@ public:
#endif #endif
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
ALWAYS_INLINE bool compareTrivial(const CharT * haystack_pos, const CharT * const haystack_end, const uint8_t * needle_pos) const ALWAYS_INLINE bool compareTrivial(const CharT * haystack_pos, const CharT * const haystack_end, const uint8_t * needle_pos) const
{ {
while (haystack_pos < haystack_end && needle_pos < needle_end) while (haystack_pos < haystack_end && needle_pos < needle_end)
@ -217,7 +219,8 @@ public:
return needle_pos == needle_end; return needle_pos == needle_end;
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
ALWAYS_INLINE bool compare(const CharT * /*haystack*/, const CharT * haystack_end, const CharT * pos) const ALWAYS_INLINE bool compare(const CharT * /*haystack*/, const CharT * haystack_end, const CharT * pos) const
{ {
@ -262,7 +265,8 @@ public:
/** Returns haystack_end if not found. /** Returns haystack_end if not found.
*/ */
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
const CharT * search(const CharT * haystack, const CharT * const haystack_end) const const CharT * search(const CharT * haystack, const CharT * const haystack_end) const
{ {
if (0 == needle_size) if (0 == needle_size)
@ -338,7 +342,8 @@ public:
return haystack_end; return haystack_end;
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
const CharT * search(const CharT * haystack, const size_t haystack_size) const const CharT * search(const CharT * haystack, const size_t haystack_size) const
{ {
return search(haystack, haystack + haystack_size); return search(haystack, haystack + haystack_size);
@ -367,7 +372,8 @@ private:
#endif #endif
public: public:
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
StringSearcher(const CharT * needle_, const size_t needle_size) StringSearcher(const CharT * needle_, const size_t needle_size)
: needle{reinterpret_cast<const uint8_t *>(needle_)}, needle_end{needle + needle_size} : needle{reinterpret_cast<const uint8_t *>(needle_)}, needle_end{needle + needle_size}
{ {
@ -399,7 +405,8 @@ public:
#endif #endif
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
ALWAYS_INLINE bool compare(const CharT * /*haystack*/, const CharT * /*haystack_end*/, const CharT * pos) const ALWAYS_INLINE bool compare(const CharT * /*haystack*/, const CharT * /*haystack_end*/, const CharT * pos) const
{ {
#ifdef __SSE4_1__ #ifdef __SSE4_1__
@ -453,7 +460,8 @@ public:
return false; return false;
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
const CharT * search(const CharT * haystack, const CharT * const haystack_end) const const CharT * search(const CharT * haystack, const CharT * const haystack_end) const
{ {
if (needle == needle_end) if (needle == needle_end)
@ -540,7 +548,8 @@ public:
return haystack_end; return haystack_end;
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
const CharT * search(const CharT * haystack, const size_t haystack_size) const const CharT * search(const CharT * haystack, const size_t haystack_size) const
{ {
return search(haystack, haystack + haystack_size); return search(haystack, haystack + haystack_size);
@ -568,7 +577,8 @@ private:
#endif #endif
public: public:
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
StringSearcher(const CharT * needle_, const size_t needle_size) StringSearcher(const CharT * needle_, const size_t needle_size)
: needle{reinterpret_cast<const uint8_t *>(needle_)}, needle_end{needle + needle_size} : needle{reinterpret_cast<const uint8_t *>(needle_)}, needle_end{needle + needle_size}
{ {
@ -596,7 +606,8 @@ public:
#endif #endif
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
ALWAYS_INLINE bool compare(const CharT * /*haystack*/, const CharT * /*haystack_end*/, const CharT * pos) const ALWAYS_INLINE bool compare(const CharT * /*haystack*/, const CharT * /*haystack_end*/, const CharT * pos) const
{ {
#ifdef __SSE4_1__ #ifdef __SSE4_1__
@ -642,7 +653,8 @@ public:
return false; return false;
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
const CharT * search(const CharT * haystack, const CharT * const haystack_end) const const CharT * search(const CharT * haystack, const CharT * const haystack_end) const
{ {
if (needle == needle_end) if (needle == needle_end)
@ -722,7 +734,8 @@ public:
return haystack_end; return haystack_end;
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
const CharT * search(const CharT * haystack, const size_t haystack_size) const const CharT * search(const CharT * haystack, const size_t haystack_size) const
{ {
return search(haystack, haystack + haystack_size); return search(haystack, haystack + haystack_size);
@ -740,7 +753,8 @@ class TokenSearcher : public StringSearcherBase
size_t needle_size; size_t needle_size;
public: public:
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
TokenSearcher(const CharT * needle_, const size_t needle_size_) TokenSearcher(const CharT * needle_, const size_t needle_size_)
: searcher{needle_, needle_size_}, : searcher{needle_, needle_size_},
needle_size(needle_size_) needle_size(needle_size_)
@ -752,7 +766,8 @@ public:
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
ALWAYS_INLINE bool compare(const CharT * haystack, const CharT * haystack_end, const CharT * pos) const ALWAYS_INLINE bool compare(const CharT * haystack, const CharT * haystack_end, const CharT * pos) const
{ {
// use searcher only if pos is in the beginning of token and pos + searcher.needle_size is end of token. // use searcher only if pos is in the beginning of token and pos + searcher.needle_size is end of token.
@ -762,7 +777,8 @@ public:
return false; return false;
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
const CharT * search(const CharT * haystack, const CharT * const haystack_end) const const CharT * search(const CharT * haystack, const CharT * const haystack_end) const
{ {
// use searcher.search(), then verify that returned value is a token // use searcher.search(), then verify that returned value is a token
@ -781,13 +797,15 @@ public:
return haystack_end; return haystack_end;
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
const CharT * search(const CharT * haystack, const size_t haystack_size) const const CharT * search(const CharT * haystack, const size_t haystack_size) const
{ {
return search(haystack, haystack + haystack_size); return search(haystack, haystack + haystack_size);
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
ALWAYS_INLINE bool isToken(const CharT * haystack, const CharT * const haystack_end, const CharT* p) const ALWAYS_INLINE bool isToken(const CharT * haystack, const CharT * const haystack_end, const CharT* p) const
{ {
return (p == haystack || isTokenSeparator(*(p - 1))) return (p == haystack || isTokenSeparator(*(p - 1)))
@ -819,11 +837,13 @@ struct LibCASCIICaseSensitiveStringSearcher : public StringSearcherBase
{ {
const char * const needle; const char * const needle;
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
LibCASCIICaseSensitiveStringSearcher(const CharT * const needle_, const size_t /* needle_size */) LibCASCIICaseSensitiveStringSearcher(const CharT * const needle_, const size_t /* needle_size */)
: needle(reinterpret_cast<const char *>(needle_)) {} : needle(reinterpret_cast<const char *>(needle_)) {}
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
const CharT * search(const CharT * haystack, const CharT * const haystack_end) const const CharT * search(const CharT * haystack, const CharT * const haystack_end) const
{ {
const auto * res = strstr(reinterpret_cast<const char *>(haystack), reinterpret_cast<const char *>(needle)); const auto * res = strstr(reinterpret_cast<const char *>(haystack), reinterpret_cast<const char *>(needle));
@ -832,7 +852,8 @@ struct LibCASCIICaseSensitiveStringSearcher : public StringSearcherBase
return reinterpret_cast<const CharT *>(res); return reinterpret_cast<const CharT *>(res);
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
const CharT * search(const CharT * haystack, const size_t haystack_size) const const CharT * search(const CharT * haystack, const size_t haystack_size) const
{ {
return search(haystack, haystack + haystack_size); return search(haystack, haystack + haystack_size);
@ -843,11 +864,13 @@ struct LibCASCIICaseInsensitiveStringSearcher : public StringSearcherBase
{ {
const char * const needle; const char * const needle;
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
LibCASCIICaseInsensitiveStringSearcher(const CharT * const needle_, const size_t /* needle_size */) LibCASCIICaseInsensitiveStringSearcher(const CharT * const needle_, const size_t /* needle_size */)
: needle(reinterpret_cast<const char *>(needle_)) {} : needle(reinterpret_cast<const char *>(needle_)) {}
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
const CharT * search(const CharT * haystack, const CharT * const haystack_end) const const CharT * search(const CharT * haystack, const CharT * const haystack_end) const
{ {
const auto * res = strcasestr(reinterpret_cast<const char *>(haystack), reinterpret_cast<const char *>(needle)); const auto * res = strcasestr(reinterpret_cast<const char *>(haystack), reinterpret_cast<const char *>(needle));
@ -856,7 +879,8 @@ struct LibCASCIICaseInsensitiveStringSearcher : public StringSearcherBase
return reinterpret_cast<const CharT *>(res); return reinterpret_cast<const CharT *>(res);
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
const CharT * search(const CharT * haystack, const size_t haystack_size) const const CharT * search(const CharT * haystack, const size_t haystack_size) const
{ {
return search(haystack, haystack + haystack_size); return search(haystack, haystack + haystack_size);

View File

@ -75,7 +75,8 @@ inline size_t countCodePoints(const UInt8 * data, size_t size)
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
size_t convertCodePointToUTF8(int code_point, CharT * out_bytes, size_t out_length) size_t convertCodePointToUTF8(int code_point, CharT * out_bytes, size_t out_length)
{ {
static const Poco::UTF8Encoding utf8; static const Poco::UTF8Encoding utf8;
@ -84,7 +85,8 @@ size_t convertCodePointToUTF8(int code_point, CharT * out_bytes, size_t out_leng
return res; return res;
} }
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>> template <typename CharT>
requires (sizeof(CharT) == 1)
std::optional<uint32_t> convertUTF8ToCodePoint(const CharT * in_bytes, size_t in_length) std::optional<uint32_t> convertUTF8ToCodePoint(const CharT * in_bytes, size_t in_length)
{ {
static const Poco::UTF8Encoding utf8; static const Poco::UTF8Encoding utf8;

View File

@ -25,7 +25,8 @@ namespace DB
* In the rest, behaves like a dynamic_cast. * In the rest, behaves like a dynamic_cast.
*/ */
template <typename To, typename From> template <typename To, typename From>
std::enable_if_t<std::is_reference_v<To>, To> typeid_cast(From & from) requires std::is_reference_v<To>
To typeid_cast(From & from)
{ {
try try
{ {
@ -43,7 +44,8 @@ std::enable_if_t<std::is_reference_v<To>, To> typeid_cast(From & from)
template <typename To, typename From> template <typename To, typename From>
std::enable_if_t<std::is_pointer_v<To>, To> typeid_cast(From * from) requires std::is_pointer_v<To>
To typeid_cast(From * from)
{ {
try try
{ {
@ -60,7 +62,8 @@ std::enable_if_t<std::is_pointer_v<To>, To> typeid_cast(From * from)
template <typename To, typename From> template <typename To, typename From>
std::enable_if_t<is_shared_ptr_v<To>, To> typeid_cast(const std::shared_ptr<From> & from) requires is_shared_ptr_v<To>
To typeid_cast(const std::shared_ptr<From> & from)
{ {
try try
{ {

View File

@ -115,8 +115,8 @@ private:
} }
template <typename T, typename U> template <typename T, typename U>
static std::enable_if_t<is_decimal<T> && is_decimal<U>, Shift> requires is_decimal<T> && is_decimal<U>
getScales(const DataTypePtr & left_type, const DataTypePtr & right_type) static Shift getScales(const DataTypePtr & left_type, const DataTypePtr & right_type)
{ {
const DataTypeDecimalBase<T> * decimal0 = checkDecimalBase<T>(*left_type); const DataTypeDecimalBase<T> * decimal0 = checkDecimalBase<T>(*left_type);
const DataTypeDecimalBase<U> * decimal1 = checkDecimalBase<U>(*right_type); const DataTypeDecimalBase<U> * decimal1 = checkDecimalBase<U>(*right_type);
@ -137,8 +137,8 @@ private:
} }
template <typename T, typename U> template <typename T, typename U>
static std::enable_if_t<is_decimal<T> && !is_decimal<U>, Shift> requires is_decimal<T> && (!is_decimal<U>)
getScales(const DataTypePtr & left_type, const DataTypePtr &) static Shift getScales(const DataTypePtr & left_type, const DataTypePtr &)
{ {
Shift shift; Shift shift;
const DataTypeDecimalBase<T> * decimal0 = checkDecimalBase<T>(*left_type); const DataTypeDecimalBase<T> * decimal0 = checkDecimalBase<T>(*left_type);
@ -148,8 +148,8 @@ private:
} }
template <typename T, typename U> template <typename T, typename U>
static std::enable_if_t<!is_decimal<T> && is_decimal<U>, Shift> requires (!is_decimal<T>) && is_decimal<U>
getScales(const DataTypePtr &, const DataTypePtr & right_type) static Shift getScales(const DataTypePtr &, const DataTypePtr & right_type)
{ {
Shift shift; Shift shift;
const DataTypeDecimalBase<U> * decimal1 = checkDecimalBase<U>(*right_type); const DataTypeDecimalBase<U> * decimal1 = checkDecimalBase<U>(*right_type);

View File

@ -53,7 +53,8 @@ struct MultiEnum
return bitset; return bitset;
} }
template <typename ValueType, typename = std::enable_if_t<std::is_convertible_v<ValueType, StorageType>>> template <typename ValueType>
requires std::is_convertible_v<ValueType, StorageType>
void setValue(ValueType new_value) void setValue(ValueType new_value)
{ {
// Can't set value from any enum avoid confusion // Can't set value from any enum avoid confusion
@ -66,7 +67,8 @@ struct MultiEnum
return bitset == other.bitset; return bitset == other.bitset;
} }
template <typename ValueType, typename = std::enable_if_t<std::is_convertible_v<ValueType, StorageType>>> template <typename ValueType>
requires std::is_convertible_v<ValueType, StorageType>
bool operator==(ValueType other) const bool operator==(ValueType other) const
{ {
// Shouldn't be comparable with any enum to avoid confusion // Shouldn't be comparable with any enum to avoid confusion
@ -80,13 +82,15 @@ struct MultiEnum
return !(*this == other); return !(*this == other);
} }
template <typename ValueType, typename = std::enable_if_t<std::is_convertible_v<ValueType, StorageType>>> template <typename ValueType>
requires std::is_convertible_v<ValueType, StorageType>
friend bool operator==(ValueType left, MultiEnum right) friend bool operator==(ValueType left, MultiEnum right)
{ {
return right.operator==(left); return right.operator==(left);
} }
template <typename L, typename = typename std::enable_if<!std::is_same_v<L, MultiEnum>>::type> template <typename L>
requires (!std::is_same_v<L, MultiEnum>)
friend bool operator!=(L left, MultiEnum right) friend bool operator!=(L left, MultiEnum right)
{ {
return !(right.operator==(left)); return !(right.operator==(left));

View File

@ -7,7 +7,8 @@ namespace DB
// Use template to disable implicit casting for certain overloaded types such as Field, which leads // Use template to disable implicit casting for certain overloaded types such as Field, which leads
// to overload resolution ambiguity. // to overload resolution ambiguity.
class Field; class Field;
template <typename T, typename U = std::enable_if_t<std::is_same_v<T, Field>>> template <typename T>
requires std::is_same_v<T, Field>
std::ostream & operator<<(std::ostream & stream, const T & what); std::ostream & operator<<(std::ostream & stream, const T & what);
struct NameAndTypePair; struct NameAndTypePair;

View File

@ -14,36 +14,36 @@ namespace
{ {
template <typename T> template <typename T>
inline std::enable_if_t<std::is_integral_v<T> && (sizeof(T) <= sizeof(UInt32)), T> requires std::is_integral_v<T> && (sizeof(T) <= sizeof(UInt32))
roundDownToPowerOfTwo(T x) inline T roundDownToPowerOfTwo(T x)
{ {
return x <= 0 ? 0 : (T(1) << (31 - __builtin_clz(x))); return x <= 0 ? 0 : (T(1) << (31 - __builtin_clz(x)));
} }
template <typename T> template <typename T>
inline std::enable_if_t<std::is_integral_v<T> && (sizeof(T) == sizeof(UInt64)), T> requires std::is_integral_v<T> && (sizeof(T) == sizeof(UInt64))
roundDownToPowerOfTwo(T x) inline T roundDownToPowerOfTwo(T x)
{ {
return x <= 0 ? 0 : (T(1) << (63 - __builtin_clzll(x))); return x <= 0 ? 0 : (T(1) << (63 - __builtin_clzll(x)));
} }
template <typename T> template <typename T>
inline std::enable_if_t<std::is_same_v<T, Float32>, T> requires std::is_same_v<T, Float32>
roundDownToPowerOfTwo(T x) inline T roundDownToPowerOfTwo(T x)
{ {
return bit_cast<T>(bit_cast<UInt32>(x) & ~((1ULL << 23) - 1)); return bit_cast<T>(bit_cast<UInt32>(x) & ~((1ULL << 23) - 1));
} }
template <typename T> template <typename T>
inline std::enable_if_t<std::is_same_v<T, Float64>, T> requires std::is_same_v<T, Float64>
roundDownToPowerOfTwo(T x) inline T roundDownToPowerOfTwo(T x)
{ {
return bit_cast<T>(bit_cast<UInt64>(x) & ~((1ULL << 52) - 1)); return bit_cast<T>(bit_cast<UInt64>(x) & ~((1ULL << 52) - 1));
} }
template <typename T> template <typename T>
inline std::enable_if_t<is_big_int_v<T>, T> requires is_big_int_v<T>
roundDownToPowerOfTwo(T) inline T roundDownToPowerOfTwo(T)
{ {
throw Exception("roundToExp2() for big integers is not implemented", ErrorCodes::NOT_IMPLEMENTED); throw Exception("roundToExp2() for big integers is not implemented", ErrorCodes::NOT_IMPLEMENTED);
} }

View File

@ -966,8 +966,8 @@ inline void readDateTimeText(LocalDateTime & datetime, ReadBuffer & buf)
/// Generic methods to read value in native binary format. /// Generic methods to read value in native binary format.
template <typename T> template <typename T>
inline std::enable_if_t<is_arithmetic_v<T>, void> requires is_arithmetic_v<T>
readBinary(T & x, ReadBuffer & buf) { readPODBinary(x, buf); } inline void readBinary(T & x, ReadBuffer & buf) { readPODBinary(x, buf); }
inline void readBinary(String & x, ReadBuffer & buf) { readStringBinary(x, buf); } inline void readBinary(String & x, ReadBuffer & buf) { readStringBinary(x, buf); }
inline void readBinary(Int128 & x, ReadBuffer & buf) { readPODBinary(x, buf); } inline void readBinary(Int128 & x, ReadBuffer & buf) { readPODBinary(x, buf); }
@ -982,8 +982,8 @@ inline void readBinary(LocalDate & x, ReadBuffer & buf) { readPODBinary(x, buf);
template <typename T> template <typename T>
inline std::enable_if_t<is_arithmetic_v<T> && (sizeof(T) <= 8), void> requires is_arithmetic_v<T> && (sizeof(T) <= 8)
readBinaryBigEndian(T & x, ReadBuffer & buf) /// Assuming little endian architecture. inline void readBinaryBigEndian(T & x, ReadBuffer & buf) /// Assuming little endian architecture.
{ {
readPODBinary(x, buf); readPODBinary(x, buf);
@ -998,8 +998,8 @@ readBinaryBigEndian(T & x, ReadBuffer & buf) /// Assuming little endian archi
} }
template <typename T> template <typename T>
inline std::enable_if_t<is_big_int_v<T>, void> requires is_big_int_v<T>
readBinaryBigEndian(T & x, ReadBuffer & buf) /// Assuming little endian architecture. inline void readBinaryBigEndian(T & x, ReadBuffer & buf) /// Assuming little endian architecture.
{ {
for (size_t i = 0; i != std::size(x.items); ++i) for (size_t i = 0; i != std::size(x.items); ++i)
{ {
@ -1034,8 +1034,8 @@ inline void readText(UUID & x, ReadBuffer & buf) { readUUIDText(x, buf); }
/// Generic methods to read value in text format, /// Generic methods to read value in text format,
/// possibly in single quotes (only for data types that use quotes in VALUES format of INSERT statement in SQL). /// possibly in single quotes (only for data types that use quotes in VALUES format of INSERT statement in SQL).
template <typename T> template <typename T>
inline std::enable_if_t<is_arithmetic_v<T>, void> requires is_arithmetic_v<T>
readQuoted(T & x, ReadBuffer & buf) { readText(x, buf); } inline void readQuoted(T & x, ReadBuffer & buf) { readText(x, buf); }
inline void readQuoted(String & x, ReadBuffer & buf) { readQuotedString(x, buf); } inline void readQuoted(String & x, ReadBuffer & buf) { readQuotedString(x, buf); }
@ -1063,8 +1063,8 @@ inline void readQuoted(UUID & x, ReadBuffer & buf)
/// Same as above, but in double quotes. /// Same as above, but in double quotes.
template <typename T> template <typename T>
inline std::enable_if_t<is_arithmetic_v<T>, void> requires is_arithmetic_v<T>
readDoubleQuoted(T & x, ReadBuffer & buf) { readText(x, buf); } inline void readDoubleQuoted(T & x, ReadBuffer & buf) { readText(x, buf); }
inline void readDoubleQuoted(String & x, ReadBuffer & buf) { readDoubleQuotedString(x, buf); } inline void readDoubleQuoted(String & x, ReadBuffer & buf) { readDoubleQuotedString(x, buf); }
@ -1101,7 +1101,8 @@ inline void readCSVSimple(T & x, ReadBuffer & buf)
} }
template <typename T> template <typename T>
inline std::enable_if_t<is_arithmetic_v<T>, void> readCSV(T & x, ReadBuffer & buf) requires is_arithmetic_v<T>
inline void readCSV(T & x, ReadBuffer & buf)
{ {
readCSVSimple(x, buf); readCSVSimple(x, buf);
} }

View File

@ -108,8 +108,8 @@ inline void readVarInt(Int16 & x, ReadBuffer & istr)
} }
template <typename T> template <typename T>
inline std::enable_if_t<!std::is_same_v<T, UInt64>, void> requires (!std::is_same_v<T, UInt64>)
readVarUInt(T & x, ReadBuffer & istr) inline void readVarUInt(T & x, ReadBuffer & istr)
{ {
UInt64 tmp; UInt64 tmp;
readVarUInt(tmp, istr); readVarUInt(tmp, istr);