Skip to content

Commit 69cb210

Browse files
committed
Add KAITAI_STREAM_H_CPP11_SUPPORT macro, fix C++98 compatibility
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.
1 parent 7795aef commit 69cb210

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

kaitai/exceptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// achieve that: C++98 compilers prefer `throw()`, C++11 and later
1212
// use `noexcept`. We define KS_NOEXCEPT macro for that.
1313

14-
#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900)
14+
#ifdef KAITAI_STREAM_H_CPP11_SUPPORT
1515
#define KS_NOEXCEPT noexcept
1616
#else
1717
#define KS_NOEXCEPT throw()

kaitai/kaitaistream.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@
44
// Kaitai Struct runtime API version: x.y.z = 'xxxyyyzzz' decimal
55
#define KAITAI_STRUCT_VERSION 11000L
66

7+
// check for C++11 support - https://stackoverflow.com/a/40512515
8+
#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900)
9+
#define KAITAI_STREAM_H_CPP11_SUPPORT
10+
#endif
11+
712
#include <stdint.h> // int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t
813

914
#include <ios> // std::streamsize
1015
#include <istream> // std::istream
1116
#include <limits> // std::numeric_limits
1217
#include <sstream> // std::istringstream
1318
#include <string> // std::string
19+
20+
#ifdef KAITAI_STREAM_H_CPP11_SUPPORT
1421
#include <type_traits> // std::enable_if, std::is_integral
22+
#endif
1523

1624
namespace kaitai {
1725

@@ -229,8 +237,7 @@ class kstream {
229237
* since C++11) in older C++ implementations.
230238
*/
231239
template<typename I>
232-
// check for C++11 support - https://stackoverflow.com/a/40512515
233-
#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900)
240+
#ifdef KAITAI_STREAM_H_CPP11_SUPPORT
234241
// https://stackoverflow.com/a/27913885
235242
typename std::enable_if<
236243
std::is_integral<I>::value &&

0 commit comments

Comments
 (0)