mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
AK: Add Traits for Enums
Enums can be hashed as their underlying integral type. This allows enum keys in hash maps etc.
This commit is contained in:
parent
22b836dd7b
commit
f99e6507ee
Notes:
sideshowbarker
2024-07-18 05:12:37 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/f99e6507eec Pull-request: https://github.com/SerenityOS/serenity/pull/9471 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/awesomekling
1 changed files with 7 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Concepts.h>
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
#include <AK/HashFunctions.h>
|
#include <AK/HashFunctions.h>
|
||||||
|
|
||||||
|
@ -41,6 +42,12 @@ requires(IsPointer<T>) struct Traits<T> : public GenericTraits<T> {
|
||||||
static constexpr bool is_trivial() { return true; }
|
static constexpr bool is_trivial() { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<Enum T>
|
||||||
|
struct Traits<T> : public GenericTraits<T> {
|
||||||
|
static unsigned hash(T value) { return Traits<UnderlyingType<T>>::hash(to_underlying(value)); }
|
||||||
|
static constexpr bool is_trivial() { return Traits<UnderlyingType<T>>::is_trivial(); }
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using AK::GenericTraits;
|
using AK::GenericTraits;
|
||||||
|
|
Loading…
Reference in a new issue