diff --git a/include/flatbuffers/stl_emulation.h b/include/flatbuffers/stl_emulation.h index 452ddb832..fd3a8cda7 100644 --- a/include/flatbuffers/stl_emulation.h +++ b/include/flatbuffers/stl_emulation.h @@ -41,15 +41,18 @@ #include #endif -// The __cpp_lib_span is the predefined feature macro. -#if defined(FLATBUFFERS_USE_STD_SPAN) - #include -#elif defined(__cpp_lib_span) && defined(__has_include) - #if __has_include() - #include - #include - #define FLATBUFFERS_USE_STD_SPAN +#ifndef FLATBUFFERS_USE_STD_SPAN + // Testing __cpp_lib_span requires including either or , + // both of which were added in C++20. + // See: https://en.cppreference.com/w/cpp/utility/feature_test + #if defined(__cplusplus) && __cplusplus >= 202002L + #define FLATBUFFERS_USE_STD_SPAN 1 #endif +#endif // FLATBUFFERS_USE_STD_SPAN + +#if defined(FLATBUFFERS_USE_STD_SPAN) + #include + #include #else // Disable non-trivial ctors if FLATBUFFERS_SPAN_MINIMAL defined. #if !defined(FLATBUFFERS_TEMPLATES_ALIASES)