Skip to content

Commit

Permalink
Add KAITAI_STREAM_H_CPP11_SUPPORT macro, fix C++98 compatibility
Browse files Browse the repository at this point in the history
See #72 (comment)

The standard library header `<type_traits>` 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.
  • Loading branch information
generalmimon committed Jun 19, 2024
1 parent d211afd commit 8cd75f2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kaitai/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions kaitai/kaitaistream.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
#include <limits> // std::numeric_limits
#include <sstream> // std::istringstream
#include <string> // std::string

#ifdef KAITAI_STREAM_H_CPP11_SUPPORT
#include <type_traits> // std::enable_if, std::is_integral
#endif

namespace kaitai {

Expand Down Expand Up @@ -234,8 +237,7 @@ class kstream {
* since C++11) in older C++ implementations.
*/
template<typename I>
// 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<I>::value &&
Expand Down

0 comments on commit 8cd75f2

Please sign in to comment.