mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-09 23:34:23 +00:00
add namespace magic_enum::istream_operators
This commit is contained in:
parent
25d7f64dfb
commit
b6bf0aa2a8
3 changed files with 93 additions and 3 deletions
|
|
@ -1336,7 +1336,7 @@ std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& o
|
|||
using U = underlying_type_t<D>;
|
||||
|
||||
if constexpr (detail::supported<D>::value) {
|
||||
if (const auto name = magic_enum::enum_flags_name<D>(value); !name.empty()) {
|
||||
if (const auto name = enum_flags_name<D>(value); !name.empty()) {
|
||||
for (const auto c : name) {
|
||||
os.put(c);
|
||||
}
|
||||
|
|
@ -1353,6 +1353,29 @@ std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& o
|
|||
|
||||
} // namespace magic_enum::ostream_operators
|
||||
|
||||
namespace istream_operators {
|
||||
|
||||
template <typename Char, typename Traits, typename E, detail::enable_if_t<E, int> = 0>
|
||||
std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& is, E& value) {
|
||||
std::basic_string<Char, Traits> in;
|
||||
is >> in;
|
||||
if (const auto v = enum_cast<E>(in)) {
|
||||
value = *v;
|
||||
} else {
|
||||
is.setstate(std::ios::failbit);
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
} // namespace magic_enum::istream_operators
|
||||
|
||||
namespace iostream_operators {
|
||||
|
||||
using namespace ostream_operators;
|
||||
using namespace istream_operators;
|
||||
|
||||
} // namespace magic_enum::iostream_operators
|
||||
|
||||
namespace bitwise_operators {
|
||||
|
||||
template <typename E, detail::enable_if_t<E, int> = 0>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue