From 69cb210ca353c309ec18bf75b025c44da6f5210b Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Tue, 30 Apr 2024 12:24:42 +0200 Subject: [PATCH] Add `KAITAI_STREAM_H_CPP11_SUPPORT` macro, fix C++98 compatibility See https://github.com/kaitai-io/kaitai_struct_cpp_stl_runtime/pull/72#discussion_r1584395613 The standard library header `` is only available since C++11 (see https://en.cppreference.com/w/cpp/header/type_traits), so we must not try to include it in C++98 mode. --- kaitai/exceptions.h | 2 +- kaitai/kaitaistream.h | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/kaitai/exceptions.h b/kaitai/exceptions.h index 4d1c85f..589c15e 100644 --- a/kaitai/exceptions.h +++ b/kaitai/exceptions.h @@ -11,7 +11,7 @@ // achieve that: C++98 compilers prefer `throw()`, C++11 and later // use `noexcept`. We define KS_NOEXCEPT macro for that. -#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900) +#ifdef KAITAI_STREAM_H_CPP11_SUPPORT #define KS_NOEXCEPT noexcept #else #define KS_NOEXCEPT throw() diff --git a/kaitai/kaitaistream.h b/kaitai/kaitaistream.h index 9934c77..60dab0b 100644 --- a/kaitai/kaitaistream.h +++ b/kaitai/kaitaistream.h @@ -4,6 +4,11 @@ // Kaitai Struct runtime API version: x.y.z = 'xxxyyyzzz' decimal #define KAITAI_STRUCT_VERSION 11000L +// check for C++11 support - https://stackoverflow.com/a/40512515 +#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900) +#define KAITAI_STREAM_H_CPP11_SUPPORT +#endif + #include // int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t #include // std::streamsize @@ -11,7 +16,10 @@ #include // std::numeric_limits #include // std::istringstream #include // std::string + +#ifdef KAITAI_STREAM_H_CPP11_SUPPORT #include // std::enable_if, std::is_integral +#endif namespace kaitai { @@ -229,8 +237,7 @@ class kstream { * since C++11) in older C++ implementations. */ template -// check for C++11 support - https://stackoverflow.com/a/40512515 -#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900) +#ifdef KAITAI_STREAM_H_CPP11_SUPPORT // https://stackoverflow.com/a/27913885 typename std::enable_if< std::is_integral::value &&