Skip to content

Commit 12ec998

Browse files
committed
Improve code and fix compilation issues with C++98
1 parent a861ea7 commit 12ec998

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

src/BitStreamException.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ namespace kanzi
4848
{
4949
}
5050

51+
#if __cplusplus >= 201103L
52+
BitStreamException(const BitStreamException&) = default;
53+
54+
BitStreamException& operator=(const BitStreamException&) = default;
55+
#endif
56+
5157
int error() const { return _code; }
5258

5359
~BitStreamException() NOEXCEPT {}

src/concurrent.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,22 @@ limitations under the License.
4949
#include <future>
5050
#include <functional>
5151
#include <stdexcept>
52-
#endif
5352

54-
#ifdef __x86_64__
55-
#ifdef __clang__
56-
#define CPU_PAUSE() __builtin_ia32_pause()
57-
#elif __GNUC__
58-
#define CPU_PAUSE() __builtin_ia32_pause()
59-
#elif _MSC_VER
60-
#define CPU_PAUSE() _mm_pause()
53+
#ifdef __x86_64__
54+
#ifdef __clang__
55+
#define CPU_PAUSE() __builtin_ia32_pause()
56+
#elif __GNUC__
57+
#define CPU_PAUSE() __builtin_ia32_pause()
58+
#elif _MSC_VER
59+
#define CPU_PAUSE() _mm_pause()
60+
#else
61+
#define CPU_PAUSE() std::this_thread::yield();
62+
#endif
6163
#else
6264
#define CPU_PAUSE() std::this_thread::yield();
6365
#endif
6466
#else
65-
#define CPU_PAUSE() std::this_thread::yield();
67+
#define CPU_PAUSE()
6668
#endif
6769

6870

src/io/IOException.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ namespace kanzi
4343
_code = error;
4444
}
4545

46+
#if __cplusplus >= 201103L
47+
IOException(const IOException&) = default;
48+
49+
IOException& operator=(const IOException&) = default;
50+
#endif
51+
4652
int error() const { return _code; }
4753

4854
~IOException() NOEXCEPT {}

src/io/IOUtil.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ limitations under the License.
2323
#include <sys/stat.h>
2424
#include <string.h>
2525

26+
#if __cplusplus >= 201703L
27+
#include <filesystem>
28+
#endif
2629

2730
#include "../types.hpp"
2831

@@ -295,6 +298,12 @@ namespace kanzi
295298

296299
static inline bool samePaths(const std::string& f1, const std::string& f2)
297300
{
301+
#if __cplusplus >= 201703L
302+
// Simpler and safer code with C++17
303+
std::error_code ec;
304+
return std::filesystem::equivalent(f1, f2, ec);
305+
#endif
306+
298307
if (f1.compare(f2) == 0)
299308
return true;
300309

0 commit comments

Comments
 (0)