AK: Provide traits for DistinctNumeric<T>

This commit is contained in:
AnotherTest 2021-01-28 19:12:48 +03:30 committed by Andreas Kling
parent 80837d43a2
commit e55d227f93
Notes: sideshowbarker 2024-07-18 22:47:23 +09:00

View file

@ -26,6 +26,7 @@
#pragma once #pragma once
#include <AK/Traits.h>
#include <AK/Types.h> #include <AK/Types.h>
namespace AK { namespace AK {
@ -64,9 +65,9 @@ namespace AK {
* There are many more operators that do not make sense for numerical types, * There are many more operators that do not make sense for numerical types,
* or cannot be overloaded in the first place. Naturally, they are not implemented. * or cannot be overloaded in the first place. Naturally, they are not implemented.
*/ */
template<typename T, bool Incr, bool Cmp, bool Bool, bool Flags, bool Shift, bool Arith, typename X> template<typename T, typename X, bool Incr, bool Cmp, bool Bool, bool Flags, bool Shift, bool Arith>
class DistinctNumeric { class DistinctNumeric {
using Self = DistinctNumeric<T, Incr, Cmp, Bool, Flags, Shift, Arith, X>; using Self = DistinctNumeric<T, X, Incr, Cmp, Bool, Flags, Shift, Arith>;
public: public:
DistinctNumeric(T value) DistinctNumeric(T value)
@ -301,8 +302,14 @@ private:
} }
#define TYPEDEF_DISTINCT_NUMERIC_GENERAL(T, Incr, Cmp, Bool, Flags, Shift, Arith, NAME) \ #define TYPEDEF_DISTINCT_NUMERIC_GENERAL(T, Incr, Cmp, Bool, Flags, Shift, Arith, NAME) \
using NAME = DistinctNumeric<T, Incr, Cmp, Bool, Flags, Shift, Arith, struct __##NAME##_tag>; using NAME = DistinctNumeric<T, struct __##NAME##_tag, Incr, Cmp, Bool, Flags, Shift, Arith>;
#define TYPEDEF_DISTINCT_ORDERED_ID(T, NAME) TYPEDEF_DISTINCT_NUMERIC_GENERAL(T, false, true, true, false, false, false, NAME) #define TYPEDEF_DISTINCT_ORDERED_ID(T, NAME) TYPEDEF_DISTINCT_NUMERIC_GENERAL(T, false, true, true, false, false, false, NAME)
// TODO: Further type aliases? // TODO: Further type aliases?
template<typename T, typename X, auto... Args>
struct AK::Traits<AK::DistinctNumeric<T, X, Args...>> : public AK::GenericTraits<AK::DistinctNumeric<T, X, Args...>> {
static constexpr bool is_trivial() { return true; }
static constexpr auto hash(const AK::DistinctNumeric<T, X, Args...>& d) { return AK::Traits<T>::hash(d.value()); }
};
using AK::DistinctNumeric; using AK::DistinctNumeric;