mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Switch to using c++20 constraints instead of std::enable_if
This commit is contained in:
parent
c00314746a
commit
414728cc71
9 changed files with 20 additions and 20 deletions
|
@ -66,10 +66,6 @@ Checks: [-*,
|
||||||
-modernize-use-std-format,
|
-modernize-use-std-format,
|
||||||
-modernize-use-std-numbers,
|
-modernize-use-std-numbers,
|
||||||
-modernize-use-std-print,
|
-modernize-use-std-print,
|
||||||
|
|
||||||
# C++20 supports constraints but until Spicy supports building with C++20
|
|
||||||
# this one has to stay disabled.
|
|
||||||
-modernize-use-constraints,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
HeaderFilterRegex: '.h'
|
HeaderFilterRegex: '.h'
|
||||||
|
|
|
@ -129,8 +129,8 @@ public:
|
||||||
* A version of Enqueue() taking a variable number of arguments.
|
* A version of Enqueue() taking a variable number of arguments.
|
||||||
*/
|
*/
|
||||||
template<class... Args>
|
template<class... Args>
|
||||||
std::enable_if_t<std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>, ValPtr>> Enqueue(
|
requires std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>, ValPtr>
|
||||||
const EventHandlerPtr& h, Args&&... args) {
|
void Enqueue(const EventHandlerPtr& h, Args&&... args) {
|
||||||
return Enqueue(h, zeek::Args{std::forward<Args>(args)...});
|
return Enqueue(h, zeek::Args{std::forward<Args>(args)...});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,8 +104,8 @@ public:
|
||||||
* A version of Invoke() taking a variable number of individual arguments.
|
* A version of Invoke() taking a variable number of individual arguments.
|
||||||
*/
|
*/
|
||||||
template<class... Args>
|
template<class... Args>
|
||||||
std::enable_if_t<std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>, ValPtr>, ValPtr> Invoke(
|
requires std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>, ValPtr>
|
||||||
Args&&... args) const {
|
ValPtr Invoke(Args&&... args) const {
|
||||||
auto zargs = zeek::Args{std::forward<Args>(args)...};
|
auto zargs = zeek::Args{std::forward<Args>(args)...};
|
||||||
return Invoke(&zargs);
|
return Invoke(&zargs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,8 @@ public:
|
||||||
|
|
||||||
IntrusivePtr(const IntrusivePtr& other) noexcept : IntrusivePtr(NewRef{}, other.get()) {}
|
IntrusivePtr(const IntrusivePtr& other) noexcept : IntrusivePtr(NewRef{}, other.get()) {}
|
||||||
|
|
||||||
template<class U, class = std::enable_if_t<std::is_convertible_v<U*, T*>>>
|
template<class U>
|
||||||
|
requires std::is_convertible_v<U*, T*>
|
||||||
IntrusivePtr(IntrusivePtr<U> other) noexcept : ptr_(other.release()) {
|
IntrusivePtr(IntrusivePtr<U> other) noexcept : ptr_(other.release()) {
|
||||||
// nop
|
// nop
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,12 +54,12 @@ public:
|
||||||
template<size_t Size>
|
template<size_t Size>
|
||||||
constexpr Span(element_type (&arr)[Size]) noexcept : memory_block(arr), num_elements(Size) {}
|
constexpr Span(element_type (&arr)[Size]) noexcept : memory_block(arr), num_elements(Size) {}
|
||||||
|
|
||||||
template<class Container, class Data = typename Container::value_type,
|
template<class Container, class Data = typename Container::value_type>
|
||||||
class = std::enable_if_t<std::is_convertible_v<Data*, T*>>>
|
requires std::is_convertible_v<Data*, T*>
|
||||||
Span(Container& xs) noexcept : memory_block(xs.data()), num_elements(xs.size()) {}
|
Span(Container& xs) noexcept : memory_block(xs.data()), num_elements(xs.size()) {}
|
||||||
|
|
||||||
template<class Container, class Data = typename Container::value_type,
|
template<class Container, class Data = typename Container::value_type>
|
||||||
class = std::enable_if_t<std::is_convertible_v<const Data*, T*>>>
|
requires std::is_convertible_v<const Data*, T*>
|
||||||
Span(const Container& xs) noexcept : memory_block(xs.data()), num_elements(xs.size()) {}
|
Span(const Container& xs) noexcept : memory_block(xs.data()), num_elements(xs.size()) {}
|
||||||
|
|
||||||
constexpr Span(const Span&) noexcept = default;
|
constexpr Span(const Span&) noexcept = default;
|
||||||
|
|
|
@ -1328,7 +1328,8 @@ public:
|
||||||
// access to record fields (without requiring an intermediary Val).
|
// access to record fields (without requiring an intermediary Val).
|
||||||
// It is up to the caller to ensure that the field exists in the
|
// It is up to the caller to ensure that the field exists in the
|
||||||
// record (using HasRawField(), if necessary).
|
// record (using HasRawField(), if necessary).
|
||||||
template<typename T, typename std::enable_if_t<is_zeek_val_v<T>, bool> = true>
|
template<typename T>
|
||||||
|
requires is_zeek_val_v<T>
|
||||||
auto GetFieldAs(int field) const -> std::invoke_result_t<decltype(&T::Get), T> {
|
auto GetFieldAs(int field) const -> std::invoke_result_t<decltype(&T::Get), T> {
|
||||||
if constexpr ( std::is_same_v<T, BoolVal> || std::is_same_v<T, IntVal> || std::is_same_v<T, EnumVal> )
|
if constexpr ( std::is_same_v<T, BoolVal> || std::is_same_v<T, IntVal> || std::is_same_v<T, EnumVal> )
|
||||||
return record_val[field]->int_val;
|
return record_val[field]->int_val;
|
||||||
|
@ -1365,7 +1366,8 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename std::enable_if_t<! is_zeek_val_v<T>, bool> = true>
|
template<typename T>
|
||||||
|
requires(! is_zeek_val_v<T>)
|
||||||
T GetFieldAs(int field) const {
|
T GetFieldAs(int field) const {
|
||||||
if constexpr ( std::is_integral_v<T> && std::is_signed_v<T> )
|
if constexpr ( std::is_integral_v<T> && std::is_signed_v<T> )
|
||||||
return record_val[field]->int_val;
|
return record_val[field]->int_val;
|
||||||
|
|
|
@ -624,8 +624,8 @@ public:
|
||||||
* A version of EnqueueConnEvent() taking a variable number of arguments.
|
* A version of EnqueueConnEvent() taking a variable number of arguments.
|
||||||
*/
|
*/
|
||||||
template<class... Args>
|
template<class... Args>
|
||||||
std::enable_if_t<std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>, ValPtr>> EnqueueConnEvent(
|
requires std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>, ValPtr>
|
||||||
EventHandlerPtr h, Args&&... args) {
|
void EnqueueConnEvent(EventHandlerPtr h, Args&&... args) {
|
||||||
return EnqueueConnEvent(h, zeek::Args{std::forward<Args>(args)...});
|
return EnqueueConnEvent(h, zeek::Args{std::forward<Args>(args)...});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -493,7 +493,8 @@ public:
|
||||||
|
|
||||||
BrokerData() = default;
|
BrokerData() = default;
|
||||||
|
|
||||||
template<class DataType, class = std::enable_if_t<std::is_same_v<DataType, broker::data>>>
|
template<class DataType>
|
||||||
|
requires std::is_same_v<DataType, broker::data>
|
||||||
explicit BrokerData(DataType value) : value_(std::move(value)) {
|
explicit BrokerData(DataType value) : value_(std::move(value)) {
|
||||||
// Note: we use enable_if here to avoid nasty implicit conversions of broker::data.
|
// Note: we use enable_if here to avoid nasty implicit conversions of broker::data.
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,8 +130,8 @@ public:
|
||||||
* A version of EnqueueEvent() taking a variable number of arguments.
|
* A version of EnqueueEvent() taking a variable number of arguments.
|
||||||
*/
|
*/
|
||||||
template<class... Args>
|
template<class... Args>
|
||||||
std::enable_if_t<std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>, ValPtr>> EnqueueEvent(
|
requires std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>, ValPtr>
|
||||||
EventHandlerPtr h, analyzer::Analyzer* analyzer, Args&&... args) {
|
void EnqueueEvent(EventHandlerPtr h, analyzer::Analyzer* analyzer, Args&&... args) {
|
||||||
return EnqueueEvent(h, analyzer, zeek::Args{std::forward<Args>(args)...});
|
return EnqueueEvent(h, analyzer, zeek::Args{std::forward<Args>(args)...});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue