mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-03 12:54:12 +00:00
Make inclusion of header <optional> opt-out via macro (#7168)
* Allow suppression of including <optional> via macro * Combine preprocessor conditions * Make inclusion of header <optional> opt-in * Make inclusion of <optional> opt-out via macro * Auto-detect C++17+ when defining macro * Enclose macro expression in parentheses * Check value of macro, not whether it's defined * Fix parentheses * Don't define macro with expression using other macros The preprocessor doesn't seem to like it. * Fix parentheses
This commit is contained in:
@@ -26,16 +26,20 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
// Detect C++17 compatible compiler.
|
#ifndef FLATBUFFERS_USE_STD_OPTIONAL
|
||||||
// __cplusplus >= 201703L - a compiler has support of 'static inline' variables.
|
// Detect C++17 compatible compiler.
|
||||||
#if defined(FLATBUFFERS_USE_STD_OPTIONAL) \
|
// __cplusplus >= 201703L - a compiler has support of 'static inline' variables.
|
||||||
|| (defined(__cplusplus) && __cplusplus >= 201703L) \
|
#if (defined(__cplusplus) && __cplusplus >= 201703L) \
|
||||||
|| (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))
|
|| (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
|
||||||
|
#define FLATBUFFERS_USE_STD_OPTIONAL 1
|
||||||
|
#else
|
||||||
|
#define FLATBUFFERS_USE_STD_OPTIONAL 0
|
||||||
|
#endif // (defined(__cplusplus) && __cplusplus >= 201703L) ...
|
||||||
|
#endif // FLATBUFFERS_USE_STD_OPTIONAL
|
||||||
|
|
||||||
|
#if FLATBUFFERS_USE_STD_OPTIONAL
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#ifndef FLATBUFFERS_USE_STD_OPTIONAL
|
#endif
|
||||||
#define FLATBUFFERS_USE_STD_OPTIONAL
|
|
||||||
#endif
|
|
||||||
#endif // defined(FLATBUFFERS_USE_STD_OPTIONAL) ...
|
|
||||||
|
|
||||||
// The __cpp_lib_span is the predefined feature macro.
|
// The __cpp_lib_span is the predefined feature macro.
|
||||||
#if defined(FLATBUFFERS_USE_STD_SPAN)
|
#if defined(FLATBUFFERS_USE_STD_SPAN)
|
||||||
@@ -128,7 +132,7 @@ namespace flatbuffers {
|
|||||||
};
|
};
|
||||||
#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES)
|
#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES)
|
||||||
|
|
||||||
#ifdef FLATBUFFERS_USE_STD_OPTIONAL
|
#if FLATBUFFERS_USE_STD_OPTIONAL
|
||||||
template<class T>
|
template<class T>
|
||||||
using Optional = std::optional<T>;
|
using Optional = std::optional<T>;
|
||||||
using nullopt_t = std::nullopt_t;
|
using nullopt_t = std::nullopt_t;
|
||||||
|
|||||||
Reference in New Issue
Block a user