xtd 0.2.0
Loading...
Searching...
No Matches
enum_class_flags_without_helpers.cpp
#include <xtd/as>
#include <xtd/console>
#include <xtd/enum_class>
using namespace xtd;
enum class text_attribute {
normal = 0b0,
bold = 0b1,
italic = 0b10,
underline = 0b100,
strikeout = 0b1000
};
text_attribute operator|(text_attribute lhs, text_attribute rhs) {return static_cast<text_attribute>(static_cast<std::underlying_type<text_attribute>::type>(lhs) | static_cast<std::underlying_type<text_attribute>::type>(rhs));}
template<> struct xtd::enum_set_attribute<text_attribute> {
explicit operator auto() const noexcept {return xtd::enum_attribute::flags;}
};
template<> struct xtd::enum_register<text_attribute> {
explicit operator auto() const noexcept {return xtd::enum_collection<text_attribute> {{text_attribute::normal, "normal"}, {text_attribute::bold, "bold"}, {text_attribute::italic, "italic"}, {text_attribute::underline, "underline"}, {text_attribute::strikeout, "strikeout"}};}
};
auto main() -> int {
console::write_line("name = {}", text_attribute::bold | text_attribute::italic);
console::write_line("value = {}", enum_object(text_attribute::bold | text_attribute::italic).to_int32());
console::write_line("as<int> = {}", as<int>(text_attribute::bold | text_attribute::italic));
}
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
std::vector< std::pair< enum_t, xtd::string > > enum_collection
Represents a pair of an enum_t value and a string of an enum of type enum_t.
Definition enum_collection.hpp:24
type_t as(any_object &o)
Casts a type into another type.
Definition __as_any_object.hpp:59
@ flags
Enum flags attribute.
Definition enum_attribute.hpp:26
@ normal
Represent the exit mode when the terminates normally (via xtd::environment::exit or returning from th...
Definition exit_mode.hpp:20
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Provides the base class for enumerations.
Definition enum_object.hpp:49
Provides the registration struct for enumerations.
Definition enum_register.hpp:38
Provides the set attribute struct for enumerations.
Definition enum_set_attribute.hpp:31