|
|
@@ -17,6 +17,10 @@
|
|
|
#include <variant>
|
|
|
#include <vector>
|
|
|
|
|
|
+#if __has_include(<magic_enum.hpp>)
|
|
|
+#include <magic_enum.hpp>
|
|
|
+#endif
|
|
|
+
|
|
|
#include "string_utils/any_of.h"
|
|
|
#include "string_utils/forwards.h"
|
|
|
#include "string_utils/traits.h"
|
|
|
@@ -90,6 +94,12 @@ template <typename Out> bool cast(Out & out, std::string_view str) noexcept {
|
|
|
} else if constexpr (std::is_constructible_v<Out, std::string_view>) {
|
|
|
out = Out(str);
|
|
|
return true;
|
|
|
+#if __has_include(<magic_enum.hpp>)
|
|
|
+ } else if constexpr (std::is_enum_v<Out>) {
|
|
|
+ std::optional<Out> result = magic_enum::enum_cast<Out>(str);
|
|
|
+ out = result.value_or(out);
|
|
|
+ return result;
|
|
|
+#endif
|
|
|
} else if constexpr (std::is_integral_v<Out>) {
|
|
|
using V = std::conditional_t<std::is_unsigned_v<Out>, unsigned long, long>;
|
|
|
auto [tmp, success] = cast<V>(str);
|