mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-09 23:34:23 +00:00
move iostream_operators to magic_enum_iostream
This commit is contained in:
parent
57d7e79530
commit
ed43fd5fa2
8 changed files with 148 additions and 87 deletions
|
|
@ -24,13 +24,14 @@
|
|||
#include <string>
|
||||
|
||||
#include <magic_enum.hpp>
|
||||
#include <magic_enum_iostream.hpp>
|
||||
|
||||
enum class AnimalFlags : std::uint64_t { HasClaws = 1 << 10, CanFly = 1 << 20, EatsFish = 1 << 30, Endangered = std::uint64_t{1} << 40 };
|
||||
// Add specialization `is_flags` to force define that enum are flags.
|
||||
//template <>
|
||||
//struct magic_enum::customize::enum_range<AnimalFlags> {
|
||||
// static constexpr bool is_flags = true;
|
||||
//};
|
||||
// Add specialization `is_flags` to define that enum are flags.
|
||||
template <>
|
||||
struct magic_enum::customize::enum_range<AnimalFlags> {
|
||||
static constexpr bool is_flags = true;
|
||||
};
|
||||
|
||||
int main() {
|
||||
// Enum-flags variable to string name.
|
||||
|
|
@ -48,7 +49,7 @@ int main() {
|
|||
// AnimalFlags names: HasClaws CanFly EatsFish Endangered
|
||||
|
||||
// String name to enum-flags value.
|
||||
auto f2 = magic_enum::enum_cast<AnimalFlags>("EatsFish|CanFly");
|
||||
auto f2 = magic_enum::enum_flags_cast<AnimalFlags>("EatsFish|CanFly");
|
||||
if (f2.has_value()) {
|
||||
std::cout << "EatsFish|CanFly = " << magic_enum::enum_integer(f2.value()) << std::endl; // CanFly|EatsFish = 1074790400
|
||||
}
|
||||
|
|
@ -80,7 +81,7 @@ int main() {
|
|||
std::cout << " " << f; // Ostream operator for enum-flags.
|
||||
}
|
||||
std::cout << std::endl;
|
||||
// AnimalFlags sequence: HasClaws CanFly EatsFish Endangered
|
||||
// AnimalFlags values: HasClaws CanFly EatsFish Endangered
|
||||
|
||||
using namespace magic_enum::bitwise_operators; // out-of-the-box bitwise operators for all enums.
|
||||
// Support operators: ~, |, &, ^, |=, &=, ^=.
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <magic_enum.hpp>
|
||||
#include <magic_enum_iostream.hpp>
|
||||
|
||||
enum class Color : int { RED = -10, BLUE = 0, GREEN = 10 };
|
||||
|
||||
|
|
@ -80,7 +81,7 @@ int main() {
|
|||
std::cout << " " << c; // Ostream operator for enum.
|
||||
}
|
||||
std::cout << std::endl;
|
||||
// Color sequence: RED BLUE GREEN
|
||||
// Color values: RED BLUE GREEN
|
||||
|
||||
enum class Flags { A = 1, B = 2, C = 4, D = 8 };
|
||||
using namespace magic_enum::bitwise_operators; // out-of-the-box bitwise operators for all enums.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue