diff --git a/src/main/include/log4cxx/helpers/optional.h b/src/main/include/log4cxx/helpers/optional.h index 03140d798..0707ec67a 100644 --- a/src/main/include/log4cxx/helpers/optional.h +++ b/src/main/include/log4cxx/helpers/optional.h @@ -1,14 +1,40 @@ #ifdef __has_include // Check if __has_include is present -# if __has_include() // Check for a standard library +# if __has_include() // Check for a standard version # include +# if defined(__cpp_lib_optional) // C++ >= 17 namespace LOG4CXX_NS { template< class T > using Optional = std::optional; } +#define LOG4CXX_HAS_STD_OPTIONAL 1 +#endif # elif __has_include() // Check for an experimental version # include namespace LOG4CXX_NS { template< class T > using Optional = std::experimental::optional; } +#define LOG4CXX_HAS_STD_OPTIONAL 1 # elif __has_include() // Try with an external library # include namespace LOG4CXX_NS { template< class T > using Optional = boost::optional; } +#define LOG4CXX_HAS_STD_OPTIONAL 1 # else // Not found at all -# error "Missing " +#define LOG4CXX_HAS_STD_OPTIONAL 0 # endif -#endif \ No newline at end of file +#endif + +#if !LOG4CXX_HAS_STD_OPTIONAL // Implement a minimal Optional? +namespace LOG4CXX_NS +{ + template< class T > +class Optional : private std::pair +{ + using BaseType = std::pair; +public: + Optional() : BaseType(false, T()) {} + Optional& operator=(const T& value) + { + this->first = true; + this->second = value; + return *this; + } + bool has_value() const { return this->first; } + const T& value() const { return this->second; } +}; +} // namespace LOG4CXX_NS +#endif