Skip to content

Commit 07a8fe6

Browse files
authored
Drop pre-C++11 alternatives (#1593)
* Assume C++11 We already assume C++11 elsewhere, so all pre-11 `#ifdef` branches are dead code at this point. Fixes issue #1591 because we can just use `std::isfinite` etc. assume C++11 in json_reader.cpp as well apply clang-format * valueToString: simplify lookup of special float name
1 parent dca8a24 commit 07a8fe6

File tree

3 files changed

+9
-83
lines changed

3 files changed

+9
-83
lines changed

AUTHORS

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Baruch Siach <[email protected]>
1616
Ben Boeckel <[email protected]>
1717
Benjamin Knecht <[email protected]>
1818
Bernd Kuhls <[email protected]>
19-
Billy Donahue <billydonahue@google.com>
19+
Billy Donahue <billy.donahue@gmail.com>
2020
Braden McDorman <[email protected]>
2121
Brandon Myers <[email protected]>
2222
Brendan Drew <[email protected]>

src/lib_json/json_reader.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@
2323
#include <utility>
2424

2525
#include <cstdio>
26-
#if __cplusplus >= 201103L
27-
28-
#if !defined(sscanf)
29-
#define sscanf std::sscanf
30-
#endif
31-
32-
#endif //__cplusplus
3326

3427
#if defined(_MSC_VER)
3528
#if !defined(_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
@@ -53,11 +46,7 @@ static size_t const stackLimit_g =
5346

5447
namespace Json {
5548

56-
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
5749
using CharReaderPtr = std::unique_ptr<CharReader>;
58-
#else
59-
using CharReaderPtr = std::auto_ptr<CharReader>;
60-
#endif
6150

6251
// Implementation of class Features
6352
// ////////////////////////////////

src/lib_json/json_writer.cpp

+8-71
Original file line numberDiff line numberDiff line change
@@ -10,86 +10,23 @@
1010
#include <algorithm>
1111
#include <cassert>
1212
#include <cctype>
13+
#include <cmath>
14+
#include <cstdio>
1315
#include <cstring>
1416
#include <iomanip>
1517
#include <memory>
1618
#include <set>
1719
#include <sstream>
1820
#include <utility>
1921

20-
#if __cplusplus >= 201103L
21-
#include <cmath>
22-
#include <cstdio>
23-
24-
#if !defined(isnan)
25-
#define isnan std::isnan
26-
#endif
27-
28-
#if !defined(isfinite)
29-
#define isfinite std::isfinite
30-
#endif
31-
32-
#else
33-
#include <cmath>
34-
#include <cstdio>
35-
36-
#if defined(_MSC_VER)
37-
#if !defined(isnan)
38-
#include <float.h>
39-
#define isnan _isnan
40-
#endif
41-
42-
#if !defined(isfinite)
43-
#include <float.h>
44-
#define isfinite _finite
45-
#endif
46-
47-
#if !defined(_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
48-
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
49-
#endif //_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
50-
51-
#endif //_MSC_VER
52-
53-
#if defined(__sun) && defined(__SVR4) // Solaris
54-
#if !defined(isfinite)
55-
#include <ieeefp.h>
56-
#define isfinite finite
57-
#endif
58-
#endif
59-
60-
#if defined(__hpux)
61-
#if !defined(isfinite)
62-
#if defined(__ia64) && !defined(finite)
63-
#define isfinite(x) \
64-
((sizeof(x) == sizeof(float) ? _Isfinitef(x) : _IsFinite(x)))
65-
#endif
66-
#endif
67-
#endif
68-
69-
#if !defined(isnan)
70-
// IEEE standard states that NaN values will not compare to themselves
71-
#define isnan(x) ((x) != (x))
72-
#endif
73-
74-
#if !defined(__APPLE__)
75-
#if !defined(isfinite)
76-
#define isfinite finite
77-
#endif
78-
#endif
79-
#endif
80-
8122
#if defined(_MSC_VER)
8223
// Disable warning about strdup being deprecated.
8324
#pragma warning(disable : 4996)
8425
#endif
8526

8627
namespace Json {
8728

88-
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
8929
using StreamWriterPtr = std::unique_ptr<StreamWriter>;
90-
#else
91-
using StreamWriterPtr = std::auto_ptr<StreamWriter>;
92-
#endif
9330

9431
String valueToString(LargestInt value) {
9532
UIntToStringBuffer buffer;
@@ -129,12 +66,12 @@ String valueToString(double value, bool useSpecialFloats,
12966
// Print into the buffer. We need not request the alternative representation
13067
// that always has a decimal point because JSON doesn't distinguish the
13168
// concepts of reals and integers.
132-
if (!isfinite(value)) {
133-
static const char* const reps[2][3] = {{"NaN", "-Infinity", "Infinity"},
134-
{"null", "-1e+9999", "1e+9999"}};
135-
return reps[useSpecialFloats ? 0 : 1][isnan(value) ? 0
136-
: (value < 0) ? 1
137-
: 2];
69+
if (!std::isfinite(value)) {
70+
if (std::isnan(value))
71+
return useSpecialFloats ? "NaN" : "null";
72+
if (value < 0)
73+
return useSpecialFloats ? "-Infinity" : "-1e+9999";
74+
return useSpecialFloats ? "Infinity" : "1e+9999";
13875
}
13976

14077
String buffer(size_t(36), '\0');

0 commit comments

Comments
 (0)