Merge 330935c1d679d45060df6e71d557561f18260cc6 into 520d8ee39037c9c94aa6e708a4fd6c0fa313ae80

This commit is contained in:
jaskij 2024-02-10 17:50:14 +01:00 committed by GitHub
commit 7a9f0b9ca2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

11
enum.h
View File

@ -14,6 +14,10 @@
#include <iosfwd>
#include <stdexcept>
#if __cplusplus >= 201703L
#include <optional>
#endif
// in-line, non-#pragma warning handling
// not supported in very old compilers (namely gcc 4.4 or less)
@ -344,6 +348,13 @@ struct optional {
BETTER_ENUMS_CONSTEXPR_ const T& value() const { return _value; }
#if defined(__cpp_lib_optional) && (__cpp_lib_optional >= 201606L)
BETTER_ENUMS_CONSTEXPR_ operator std::optional<T>() const {
if(has_value()) {return {_value};}
return std::nullopt;
}
#endif
private:
bool _valid;
T _value;