From 8cd75f213d45322955641d3945dd38002517f0de 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 | 6 ++++-- 2 files changed, 5 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 34b3cf0..60dab0b 100644 --- a/kaitai/kaitaistream.h +++ b/kaitai/kaitaistream.h @@ -16,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 { @@ -234,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 &&