Skip to content

Commit

Permalink
Drop pre-C++11 alternatives (#1593)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
BillyDonahue authored Jan 10, 2025
1 parent dca8a24 commit 07a8fe6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 83 deletions.
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Baruch Siach <[email protected]>
Ben Boeckel <[email protected]>
Benjamin Knecht <[email protected]>
Bernd Kuhls <[email protected]>
Billy Donahue <billydonahue@google.com>
Billy Donahue <billy.donahue@gmail.com>
Braden McDorman <[email protected]>
Brandon Myers <[email protected]>
Brendan Drew <[email protected]>
Expand Down
11 changes: 0 additions & 11 deletions src/lib_json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
#include <utility>

#include <cstdio>
#if __cplusplus >= 201103L

#if !defined(sscanf)
#define sscanf std::sscanf
#endif

#endif //__cplusplus

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

namespace Json {

#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
using CharReaderPtr = std::unique_ptr<CharReader>;
#else
using CharReaderPtr = std::auto_ptr<CharReader>;
#endif

// Implementation of class Features
// ////////////////////////////////
Expand Down
79 changes: 8 additions & 71 deletions src/lib_json/json_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,86 +10,23 @@
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <memory>
#include <set>
#include <sstream>
#include <utility>

#if __cplusplus >= 201103L
#include <cmath>
#include <cstdio>

#if !defined(isnan)
#define isnan std::isnan
#endif

#if !defined(isfinite)
#define isfinite std::isfinite
#endif

#else
#include <cmath>
#include <cstdio>

#if defined(_MSC_VER)
#if !defined(isnan)
#include <float.h>
#define isnan _isnan
#endif

#if !defined(isfinite)
#include <float.h>
#define isfinite _finite
#endif

#if !defined(_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#endif //_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES

#endif //_MSC_VER

#if defined(__sun) && defined(__SVR4) // Solaris
#if !defined(isfinite)
#include <ieeefp.h>
#define isfinite finite
#endif
#endif

#if defined(__hpux)
#if !defined(isfinite)
#if defined(__ia64) && !defined(finite)
#define isfinite(x) \
((sizeof(x) == sizeof(float) ? _Isfinitef(x) : _IsFinite(x)))
#endif
#endif
#endif

#if !defined(isnan)
// IEEE standard states that NaN values will not compare to themselves
#define isnan(x) ((x) != (x))
#endif

#if !defined(__APPLE__)
#if !defined(isfinite)
#define isfinite finite
#endif
#endif
#endif

#if defined(_MSC_VER)
// Disable warning about strdup being deprecated.
#pragma warning(disable : 4996)
#endif

namespace Json {

#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
using StreamWriterPtr = std::unique_ptr<StreamWriter>;
#else
using StreamWriterPtr = std::auto_ptr<StreamWriter>;
#endif

String valueToString(LargestInt value) {
UIntToStringBuffer buffer;
Expand Down Expand Up @@ -129,12 +66,12 @@ String valueToString(double value, bool useSpecialFloats,
// Print into the buffer. We need not request the alternative representation
// that always has a decimal point because JSON doesn't distinguish the
// concepts of reals and integers.
if (!isfinite(value)) {
static const char* const reps[2][3] = {{"NaN", "-Infinity", "Infinity"},
{"null", "-1e+9999", "1e+9999"}};
return reps[useSpecialFloats ? 0 : 1][isnan(value) ? 0
: (value < 0) ? 1
: 2];
if (!std::isfinite(value)) {
if (std::isnan(value))
return useSpecialFloats ? "NaN" : "null";
if (value < 0)
return useSpecialFloats ? "-Infinity" : "-1e+9999";
return useSpecialFloats ? "Infinity" : "1e+9999";
}

String buffer(size_t(36), '\0');
Expand Down

0 comments on commit 07a8fe6

Please sign in to comment.