54#ifndef WXMAXIMA_ENUMWRAPPER_H
55#define WXMAXIMA_ENUMWRAPPER_H
71template <
typename Enum,
typename Storage, Enum defaultValue = Enum{},
72 typename std::enable_if<std::is_enum<Enum>::value &&
73 std::is_integral<Storage>::value,
76 Storage value = Storage(defaultValue);
80 Enum(Storage(defaultValue)) == defaultValue,
81 "The default value doesn't survive a roundtrip through this wrapper.");
84 sizeof(Storage) <
sizeof(Enum),
85 "EnumWrapper should be used only to save space."
86 "When removing it, don't forget to take care of default value!");
92 constexpr EnumWrapper(Enum value) noexcept : value(value) {}
93 constexpr operator Enum()
const noexcept {
return Enum(value); }
94 constexpr operator Storage()
const =
delete;
95 constexpr std::size_t hash()
const {
return std::hash<Storage>()(value); }
97 constexpr bool operator==(
EnumWrapper o)
const {
return value == o.value; }
98 constexpr bool operator==(Enum o)
const {
return value == o; }
99 constexpr bool operator!=(
EnumWrapper o)
const {
return value != o.value; }
100 constexpr bool operator!=(Enum o)
const {
return value != o; }
103template <
typename E,
typename S, E defVal>
106template <
typename E,
typename S, E defVal>
111 template <
typename Enum,
typename Storage, Enum defaultValue>
Definition: diagrams_e.h:4
A wrapper for legacy enumerated types that can be stored in a type smaller than an int.
Definition: EnumWrapper.h:75