mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Provide traits for DistinctNumeric<T>
This commit is contained in:
parent
80837d43a2
commit
e55d227f93
Notes:
sideshowbarker
2024-07-18 22:47:23 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/e55d227f937 Pull-request: https://github.com/SerenityOS/serenity/pull/5144 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/tomuta
1 changed files with 10 additions and 3 deletions
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue