xtd 0.2.0
Loading...
Searching...
No Matches
parse_enum_struct.cpp

Shows how to use format xtd::parse<num struct> method with enum struct values.

#include <xtd/console>
#include <xtd/enum_struct>
#include <xtd/parse>
using namespace xtd;
enum_struct_(, week_day,
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
sunday
);
auto main() -> int {
auto wd1 = parse<week_day>("wednesday");
console::write_line(wd1);
auto wd2 = enum_object<>::parse<week_day>("WEDNESDAY", true);
console::write_line(wd2);
auto wd3 = parse<week_day>("2");
console::write_line(wd3);
try {
auto wd4 = parse<week_day>("january");
console::write_line(wd4);
} catch (const system_exception& e) {
console::write_line("Exception : {}", e.message());
}
}
// This code produces the following output :
//
// wednesday
// wednesday
// wednesday
// Exception : invalid character found
Provides the base class for enumerations.
Definition enum_object.h:42
The exception that is thrown when a method call is invalid for the object's current state.
Definition system_exception.h:18
#define enum_struct_(namespace_name, enum_struct_t,...)
Provides the registration struct for enum struct.
Definition enum_struct.h:52
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10