mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
Some general modernizations of templates Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/65148 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
40 lines
1.2 KiB
C++
40 lines
1.2 KiB
C++
#ifndef SRC_NODE_CONCEPTS_H_
|
|
#define SRC_NODE_CONCEPTS_H_
|
|
|
|
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
|
|
#include <concepts>
|
|
#include <limits>
|
|
#include <type_traits>
|
|
|
|
namespace node {
|
|
|
|
// A numeric type recognized by std::numeric_limits.
|
|
// The is_array guard prevents a hard error from instantiating
|
|
// numeric_limits<T[N]>, whose member functions would return array types.
|
|
template <typename T>
|
|
concept NumericValue = !
|
|
std::is_array_v<T>&& std::numeric_limits<T>::is_specialized;
|
|
|
|
// A numeric type or an enum (which has an underlying numeric type).
|
|
template <typename T>
|
|
concept NumericOrEnum = NumericValue<T> || std::is_enum_v<T>;
|
|
|
|
// A type that has a valid std::char_traits specialization, as required by
|
|
// std::basic_string and std::basic_string_view.
|
|
template <typename T>
|
|
concept StandardCharType =
|
|
std::is_same_v<T, char> || std::is_same_v<T, wchar_t> ||
|
|
std::is_same_v<T, char8_t> || std::is_same_v<T, char16_t> ||
|
|
std::is_same_v<T, char32_t>;
|
|
|
|
// Test whether some value can be called with ().
|
|
template <typename T>
|
|
concept IsCallable = std::is_function<T>::value || requires { &T::operator(); };
|
|
|
|
} // namespace node
|
|
|
|
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
|
|
#endif // SRC_NODE_CONCEPTS_H_
|