Skip to content

Commit d148241

Browse files
committed
Removing CXX20 support
1 parent dd04b5e commit d148241

File tree

8 files changed

+51
-107
lines changed

8 files changed

+51
-107
lines changed

.github/workflows/vs16-cxx20.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: VS16-CI C++20
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
ci:
7+
name: windows-vs16
8+
runs-on: windows-latest
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
include:
13+
- {gen: Visual Studio 16 2019, arch: Win32}
14+
- {gen: Visual Studio 16 2019, arch: x64}
15+
steps:
16+
- name: checkout
17+
uses: actions/checkout@v2
18+
- name: Use cmake
19+
run: |
20+
mkdir build &&
21+
cd build &&
22+
cmake ${{matrix.cxx}} ${{matrix.arch}} -DCMAKE_CXX_STANDARD=20 -DFASTFLOAT_TEST=ON -DCMAKE_INSTALL_PREFIX:PATH=destination .. &&
23+
cmake --build . --verbose &&
24+
ctest --output-on-failure

include/fast_float/ascii_number.h

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,15 @@
66
#include <cstring>
77
#include <iterator>
88

9-
#if defined __has_include
10-
#if __has_include(<version>)
11-
#include <version>
12-
#if defined(__cpp_lib_bit_cast)
13-
#include <bit>
14-
#endif
15-
#endif
16-
#endif
17-
189
#include "float_common.h"
1910

2011
namespace fast_float {
2112

2213
// Next function can be micro-optimized, but compilers are entirely
2314
// able to optimize it well.
24-
CXX20_CONSTEXPR fastfloat_really_inline bool is_integer(char c) noexcept { return c >= '0' && c <= '9'; }
15+
fastfloat_really_inline bool is_integer(char c) noexcept { return c >= '0' && c <= '9'; }
2516

26-
CXX20_CONSTEXPR fastfloat_really_inline uint64_t byteswap(uint64_t val) {
17+
fastfloat_really_inline uint64_t byteswap(uint64_t val) {
2718
return (val & 0xFF00000000000000) >> 56
2819
| (val & 0x00FF000000000000) >> 40
2920
| (val & 0x0000FF0000000000) >> 24
@@ -34,40 +25,26 @@ CXX20_CONSTEXPR fastfloat_really_inline uint64_t byteswap(uint64_t val) {
3425
| (val & 0x00000000000000FF) << 56;
3526
}
3627

37-
CXX20_CONSTEXPR fastfloat_really_inline uint64_t read_u64(const char *chars) {
28+
fastfloat_really_inline uint64_t read_u64(const char *chars) {
3829
uint64_t val;
39-
#if defined(__cpp_lib_bit_cast)
40-
val = std::bit_cast<uint64_t>(reinterpret_cast<const char (&)[8]>(chars));
41-
#else
4230
::memcpy(&val, chars, sizeof(uint64_t));
43-
#endif
4431
#if FASTFLOAT_IS_BIG_ENDIAN == 1
4532
// Need to read as-if the number was in little-endian order.
4633
val = byteswap(val);
4734
#endif
4835
return val;
4936
}
5037

51-
CXX20_CONSTEXPR fastfloat_really_inline void write_u64(uint8_t *chars, uint64_t val) {
38+
fastfloat_really_inline void write_u64(uint8_t *chars, uint64_t val) {
5239
#if FASTFLOAT_IS_BIG_ENDIAN == 1
5340
// Need to read as-if the number was in little-endian order.
5441
val = byteswap(val);
5542
#endif
56-
#if defined(__cpp_lib_bit_cast)
57-
if (std::is_constant_evaluated()) {
58-
char (&dst)[8] = reinterpret_cast<char (&)[8]>(chars);
59-
const char (&src)[8] = reinterpret_cast<const char (&)[8]>(val);
60-
std::copy(std::begin(src), std::end(src), std::begin(dst));
61-
} else {
62-
::memcpy(chars, &val, sizeof(uint64_t));
63-
}
64-
#else
6543
::memcpy(chars, &val, sizeof(uint64_t));
66-
#endif
6744
}
6845

6946
// credit @aqrit
70-
CXX20_CONSTEXPR fastfloat_really_inline uint32_t parse_eight_digits_unrolled(uint64_t val) {
47+
fastfloat_really_inline uint32_t parse_eight_digits_unrolled(uint64_t val) {
7148
const uint64_t mask = 0x000000FF000000FF;
7249
const uint64_t mul1 = 0x000F424000000064; // 100 + (1000000ULL << 32)
7350
const uint64_t mul2 = 0x0000271000000001; // 1 + (10000ULL << 32)
@@ -77,17 +54,17 @@ CXX20_CONSTEXPR fastfloat_really_inline uint32_t parse_eight_digits_unrolled(ui
7754
return uint32_t(val);
7855
}
7956

80-
CXX20_CONSTEXPR fastfloat_really_inline uint32_t parse_eight_digits_unrolled(const char *chars) noexcept {
57+
fastfloat_really_inline uint32_t parse_eight_digits_unrolled(const char *chars) noexcept {
8158
return parse_eight_digits_unrolled(read_u64(chars));
8259
}
8360

8461
// credit @aqrit
85-
CXX20_CONSTEXPR fastfloat_really_inline bool is_made_of_eight_digits_fast(uint64_t val) noexcept {
62+
fastfloat_really_inline bool is_made_of_eight_digits_fast(uint64_t val) noexcept {
8663
return !((((val + 0x4646464646464646) | (val - 0x3030303030303030)) &
8764
0x8080808080808080));
8865
}
8966

90-
CXX20_CONSTEXPR fastfloat_really_inline bool is_made_of_eight_digits_fast(const char *chars) noexcept {
67+
fastfloat_really_inline bool is_made_of_eight_digits_fast(const char *chars) noexcept {
9168
return is_made_of_eight_digits_fast(read_u64(chars));
9269
}
9370

@@ -107,7 +84,7 @@ struct parsed_number_string {
10784

10885
// Assuming that you use no more than 19 digits, this will
10986
// parse an ASCII string.
110-
CXX20_CONSTEXPR fastfloat_really_inline
87+
fastfloat_really_inline
11188
parsed_number_string parse_number_string(const char *p, const char *pend, parse_options options) noexcept {
11289
const chars_format fmt = options.format;
11390
const char decimal_point = options.decimal_point;

include/fast_float/decimal_to_binary.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace fast_float {
1717
// low part corresponding to the least significant bits.
1818
//
1919
template <int bit_precision>
20-
CXX20_CONSTEXPR fastfloat_really_inline
20+
fastfloat_really_inline
2121
value128 compute_product_approximation(int64_t q, uint64_t w) {
2222
const int index = 2 * int(q - powers::smallest_power_of_five);
2323
// For small values of q, e.g., q in [0,27], the answer is always exact because
@@ -90,7 +90,7 @@ adjusted_mantissa compute_error(int64_t q, uint64_t w) noexcept {
9090
// return an adjusted_mantissa with a negative power of 2: the caller should recompute
9191
// in such cases.
9292
template <typename binary>
93-
CXX20_CONSTEXPR fastfloat_really_inline
93+
fastfloat_really_inline
9494
adjusted_mantissa compute_float(int64_t q, uint64_t w) noexcept {
9595
adjusted_mantissa answer;
9696
if ((w == 0) || (q < binary::smallest_power_of_ten())) {

include/fast_float/fast_float.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
#ifndef FASTFLOAT_FAST_FLOAT_H
22
#define FASTFLOAT_FAST_FLOAT_H
33

4-
54
#include <system_error>
65

7-
#if !defined(CXX20_CONSTEXPR)
8-
#define CXX20_CONSTEXPR
9-
#if defined __has_include
10-
#if __has_include(<version>)
11-
#include <version>
12-
#if defined(__cpp_lib_bit_cast)
13-
#undef CXX20_CONSTEXPR
14-
#define CXX20_CONSTEXPR constexpr
15-
#define HAS_CXX20_CONSTEXPR 1
16-
#endif
17-
#endif
18-
#endif
19-
#endif
20-
216
namespace fast_float {
227
enum chars_format {
238
scientific = 1<<0,
@@ -63,14 +48,14 @@ struct parse_options {
6348
* The default is `fast_float::chars_format::general` which allows both `fixed` and `scientific`.
6449
*/
6550
template<typename T>
66-
CXX20_CONSTEXPR from_chars_result from_chars(const char *first, const char *last,
51+
from_chars_result from_chars(const char *first, const char *last,
6752
T &value, chars_format fmt = chars_format::general) noexcept;
6853

6954
/**
7055
* Like from_chars, but accepts an `options` argument to govern number parsing.
7156
*/
7257
template<typename T>
73-
CXX20_CONSTEXPR from_chars_result from_chars_advanced(const char *first, const char *last,
58+
from_chars_result from_chars_advanced(const char *first, const char *last,
7459
T &value, parse_options options) noexcept;
7560

7661
}

include/fast_float/float_common.h

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,6 @@
7474
#define fastfloat_really_inline inline __attribute__((always_inline))
7575
#endif
7676

77-
#if !defined(CXX20_CONSTEXPR)
78-
#define CXX20_CONSTEXPR
79-
#if defined __has_include
80-
#if __has_include(<version>)
81-
#include <version>
82-
#if defined(__cpp_lib_bit_cast)
83-
#undef CXX20_CONSTEXPR
84-
#define CXX20_CONSTEXPR constexpr
85-
#define HAS_CXX20_CONSTEXPR 1
86-
#endif
87-
#endif
88-
#endif
89-
#endif
90-
9177
#ifndef FASTFLOAT_ASSERT
9278
#define FASTFLOAT_ASSERT(x) { if (!(x)) abort(); }
9379
#endif
@@ -103,7 +89,7 @@
10389
namespace fast_float {
10490

10591
// Compares two ASCII strings in a case insensitive manner.
106-
CXX20_CONSTEXPR inline bool fastfloat_strncasecmp(const char *input1, const char *input2,
92+
inline bool fastfloat_strncasecmp(const char *input1, const char *input2,
10793
size_t length) {
10894
char running_diff{0};
10995
for (size_t i = 0; i < length; i++) {
@@ -142,7 +128,7 @@ struct value128 {
142128
};
143129

144130
/* result might be undefined when input_num is zero */
145-
CXX20_CONSTEXPR fastfloat_really_inline int leading_zeroes(uint64_t input_num) {
131+
fastfloat_really_inline int leading_zeroes(uint64_t input_num) {
146132
assert(input_num > 0);
147133
#ifdef FASTFLOAT_VISUAL_STUDIO
148134
#if defined(_M_X64) || defined(_M_ARM64)
@@ -169,13 +155,13 @@ CXX20_CONSTEXPR fastfloat_really_inline int leading_zeroes(uint64_t input_num) {
169155
#ifdef FASTFLOAT_32BIT
170156

171157
// slow emulation routine for 32-bit
172-
CXX20_CONSTEXPR fastfloat_really_inline uint64_t emulu(uint32_t x, uint32_t y) {
158+
fastfloat_really_inline uint64_t emulu(uint32_t x, uint32_t y) {
173159
return x * (uint64_t)y;
174160
}
175161

176162
// slow emulation routine for 32-bit
177163
#if !defined(__MINGW64__)
178-
CXX20_CONSTEXPR fastfloat_really_inline uint64_t _umul128(uint64_t ab, uint64_t cd,
164+
fastfloat_really_inline uint64_t _umul128(uint64_t ab, uint64_t cd,
179165
uint64_t *hi) {
180166
uint64_t ad = emulu((uint32_t)(ab >> 32), (uint32_t)cd);
181167
uint64_t bd = emulu((uint32_t)ab, (uint32_t)cd);
@@ -354,7 +340,6 @@ template <> inline constexpr size_t binary_format<float>::max_digits() {
354340
}
355341

356342
template<typename T>
357-
CXX20_CONSTEXPR
358343
fastfloat_really_inline void to_float(bool negative, adjusted_mantissa am, T &value) {
359344
uint64_t word = am.mantissa;
360345
word |= uint64_t(am.power2) << binary_format<T>::mantissa_explicit_bits();

include/fast_float/parse_number.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace detail {
2020
* strings a null-free and fixed.
2121
**/
2222
template <typename T>
23-
CXX20_CONSTEXPR from_chars_result parse_infnan(const char *first, const char *last, T &value) noexcept {
23+
from_chars_result parse_infnan(const char *first, const char *last, T &value) noexcept {
2424
from_chars_result answer;
2525
answer.ptr = first;
2626
answer.ec = std::errc(); // be optimistic
@@ -63,13 +63,13 @@ CXX20_CONSTEXPR from_chars_result parse_infnan(const char *first, const char *la
6363
} // namespace detail
6464

6565
template<typename T>
66-
CXX20_CONSTEXPR from_chars_result from_chars(const char *first, const char *last,
66+
from_chars_result from_chars(const char *first, const char *last,
6767
T &value, chars_format fmt /*= chars_format::general*/) noexcept {
6868
return from_chars_advanced(first, last, value, parse_options{fmt});
6969
}
7070

7171
template<typename T>
72-
CXX20_CONSTEXPR from_chars_result from_chars_advanced(const char *first, const char *last,
72+
from_chars_result from_chars_advanced(const char *first, const char *last,
7373
T &value, parse_options options) noexcept {
7474

7575
static_assert (std::is_same<T, double>::value || std::is_same<T, float>::value, "only float and double are supported");

include/fast_float/simple_decimal_conversion.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ namespace fast_float {
2222
namespace detail {
2323

2424
// remove all final zeroes
25-
CXX20_CONSTEXPR inline void trim(decimal &h) {
25+
inline void trim(decimal &h) {
2626
while ((h.num_digits > 0) && (h.digits[h.num_digits - 1] == 0)) {
2727
h.num_digits--;
2828
}
2929
}
3030

3131

3232

33-
CXX20_CONSTEXPR inline uint32_t number_of_digits_decimal_left_shift(const decimal &h, uint32_t shift) {
33+
inline uint32_t number_of_digits_decimal_left_shift(const decimal &h, uint32_t shift) {
3434
shift &= 63;
3535
constexpr uint16_t number_of_digits_decimal_left_shift_table[65] = {
3636
0x0000, 0x0800, 0x0801, 0x0803, 0x1006, 0x1009, 0x100D, 0x1812, 0x1817,
@@ -123,7 +123,7 @@ CXX20_CONSTEXPR inline uint32_t number_of_digits_decimal_left_shift(const decima
123123
return num_new_digits;
124124
}
125125

126-
CXX20_CONSTEXPR inline uint64_t round(decimal &h) {
126+
inline uint64_t round(decimal &h) {
127127
if ((h.num_digits == 0) || (h.decimal_point < 0)) {
128128
return 0;
129129
} else if (h.decimal_point > 18) {
@@ -150,7 +150,7 @@ CXX20_CONSTEXPR inline uint64_t round(decimal &h) {
150150
}
151151

152152
// computes h * 2^-shift
153-
CXX20_CONSTEXPR inline void decimal_left_shift(decimal &h, uint32_t shift) {
153+
inline void decimal_left_shift(decimal &h, uint32_t shift) {
154154
if (h.num_digits == 0) {
155155
return;
156156
}
@@ -192,7 +192,7 @@ CXX20_CONSTEXPR inline void decimal_left_shift(decimal &h, uint32_t shift) {
192192
}
193193

194194
// computes h * 2^shift
195-
CXX20_CONSTEXPR inline void decimal_right_shift(decimal &h, uint32_t shift) {
195+
inline void decimal_right_shift(decimal &h, uint32_t shift) {
196196
uint32_t read_index = 0;
197197
uint32_t write_index = 0;
198198

@@ -241,7 +241,7 @@ CXX20_CONSTEXPR inline void decimal_right_shift(decimal &h, uint32_t shift) {
241241
} // namespace detail
242242

243243
template <typename binary>
244-
CXX20_CONSTEXPR adjusted_mantissa compute_float(decimal &d) {
244+
adjusted_mantissa compute_float(decimal &d) {
245245
adjusted_mantissa answer;
246246
if (d.num_digits == 0) {
247247
// should be zero
@@ -351,7 +351,7 @@ CXX20_CONSTEXPR adjusted_mantissa compute_float(decimal &d) {
351351
}
352352

353353
template <typename binary>
354-
CXX20_CONSTEXPR adjusted_mantissa parse_long_mantissa(const char *first, const char* last, parse_options options) {
354+
adjusted_mantissa parse_long_mantissa(const char *first, const char* last, parse_options options) {
355355
decimal d = parse_decimal(first, last, options);
356356
return compute_float<binary>(d);
357357
}

tests/basictest.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@
4242
#define FASTFLOAT_ODDPLATFORM 1
4343
#endif
4444

45-
#if HAS_CXX20_CONSTEXPR
46-
#include <bit>
47-
#include <string_view>
48-
#endif
49-
5045
// C++ 17 because it is otherwise annoying to browse all files in a directory.
5146
// We also only run these tests on little endian systems.
5247
#if (FASTFLOAT_CPLUSPLUS >= 201703L) && (FASTFLOAT_IS_BIG_ENDIAN == 0) && !defined(FASTFLOAT_ODDPLATFORM)
@@ -120,28 +115,6 @@ TEST_CASE("supplemental") {
120115
}
121116
#endif
122117

123-
#if HAS_CXX20_CONSTEXPR
124-
125-
constexpr double tryParse(std::string_view input)
126-
{
127-
double result{};
128-
fast_float::from_chars_result parseResult = fast_float::from_chars(input.data(), input.data() + input.size(), result);
129-
if (parseResult.ec != std::errc()) {
130-
return std::numeric_limits<double>::quiet_NaN();
131-
}
132-
return result;
133-
}
134-
135-
static_assert(tryParse("1.0") == 1.0);
136-
static_assert(tryParse("2.0") == 2.0);
137-
static_assert(tryParse("3.14156") == 3.14156);
138-
static_assert(tryParse("3.14156") != 3.1415600000001);
139-
#if !defined(_MSVC_LANG)
140-
static_assert(std::isnan(tryParse("hellothere"))); // technically isnan is not constexpr but GCC and clang allow it
141-
#endif
142-
143-
#endif //#if HAS_CXX20_CONSTEXPR
144-
145118
TEST_CASE("leading_zeroes") {
146119
constexpr const uint64_t bit = 1;
147120
CHECK(fast_float::leading_zeroes(bit << 0) == 63);

0 commit comments

Comments
 (0)