Skip to content

Commit 8411682

Browse files
committed
add C++11 support
1 parent 369e4d1 commit 8411682

File tree

10 files changed

+145
-72
lines changed

10 files changed

+145
-72
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ add_library(rapidfuzz INTERFACE)
5050
# provide a namespaced alias for clients to 'link' against if RapidFuzz is included as a sub-project
5151
add_library(rapidfuzz::rapidfuzz ALIAS rapidfuzz)
5252

53-
target_compile_features(rapidfuzz INTERFACE cxx_std_14)
53+
target_compile_features(rapidfuzz INTERFACE cxx_std_11)
5454

5555
target_include_directories(rapidfuzz
5656
INTERFACE

extras/rapidfuzz_amalgamated.hpp

+72-36
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
22
// SPDX-License-Identifier: MIT
33
// RapidFuzz v1.0.2
4-
// Generated: 2024-12-25 02:45:23.298368
4+
// Generated: 2024-12-25 03:52:00.425895
55
// ----------------------------------------------------------
66
// This file is an amalgamation of multiple different files.
77
// You probably shouldn't edit it directly.
@@ -392,12 +392,12 @@ struct ShiftedBitMatrix {
392392
return bool(m_matrix[row][col_word] & col_mask);
393393
}
394394

395-
auto operator[](size_t row) noexcept
395+
BitMatrixView<value_type, false> operator[](size_t row) noexcept
396396
{
397397
return m_matrix[row];
398398
}
399399

400-
auto operator[](size_t row) const noexcept
400+
BitMatrixView<value_type, true> operator[](size_t row) const noexcept
401401
{
402402
return m_matrix[row];
403403
}
@@ -436,6 +436,12 @@ struct ShiftedBitMatrix {
436436
# define RAPIDFUZZ_IF_CONSTEXPR if
437437
#endif
438438

439+
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) || __cplusplus >= 201402L)
440+
# define RAPIDFUZZ_CONSTEXPR_CXX14 constexpr
441+
#else
442+
# define RAPIDFUZZ_CONSTEXPR_CXX14
443+
#endif
444+
439445
#include <stddef.h>
440446
#include <stdexcept>
441447
#include <vector>
@@ -1088,18 +1094,27 @@ static inline void assume(bool b)
10881094
#endif
10891095
}
10901096

1097+
namespace to_begin_detail {
1098+
using std::begin;
1099+
10911100
template <typename CharT>
10921101
CharT* to_begin(CharT* s)
10931102
{
10941103
return s;
10951104
}
10961105

10971106
template <typename T>
1098-
auto to_begin(T& x)
1107+
auto to_begin(T& x) -> decltype(begin(x))
10991108
{
1100-
using std::begin;
1109+
11011110
return begin(x);
11021111
}
1112+
} // namespace to_begin_detail
1113+
1114+
using to_begin_detail::to_begin;
1115+
1116+
namespace to_end_detail {
1117+
using std::end;
11031118

11041119
template <typename CharT>
11051120
CharT* to_end(CharT* s)
@@ -1112,11 +1127,13 @@ CharT* to_end(CharT* s)
11121127
}
11131128

11141129
template <typename T>
1115-
auto to_end(T& x)
1130+
auto to_end(T& x) -> decltype(end(x))
11161131
{
1117-
using std::end;
11181132
return end(x);
11191133
}
1134+
} // namespace to_end_detail
1135+
1136+
using to_end_detail::to_end;
11201137

11211138
template <typename Iter>
11221139
class Range {
@@ -1131,47 +1148,47 @@ class Range {
11311148
using iterator = Iter;
11321149
using reverse_iterator = std::reverse_iterator<iterator>;
11331150

1134-
constexpr Range(Iter first, Iter last) : _first(first), _last(last)
1151+
Range(Iter first, Iter last) : _first(first), _last(last)
11351152
{
11361153
assert(std::distance(_first, _last) >= 0);
11371154
_size = static_cast<size_t>(std::distance(_first, _last));
11381155
}
11391156

1140-
constexpr Range(Iter first, Iter last, size_t size) : _first(first), _last(last), _size(size)
1157+
Range(Iter first, Iter last, size_t size) : _first(first), _last(last), _size(size)
11411158
{}
11421159

11431160
template <typename T>
1144-
constexpr Range(T& x) : Range(to_begin(x), to_end(x))
1161+
Range(T& x) : Range(to_begin(x), to_end(x))
11451162
{}
11461163

1147-
constexpr iterator begin() const noexcept
1164+
iterator begin() const noexcept
11481165
{
11491166
return _first;
11501167
}
1151-
constexpr iterator end() const noexcept
1168+
iterator end() const noexcept
11521169
{
11531170
return _last;
11541171
}
11551172

1156-
constexpr reverse_iterator rbegin() const noexcept
1173+
reverse_iterator rbegin() const noexcept
11571174
{
11581175
return reverse_iterator(end());
11591176
}
1160-
constexpr reverse_iterator rend() const noexcept
1177+
reverse_iterator rend() const noexcept
11611178
{
11621179
return reverse_iterator(begin());
11631180
}
11641181

1165-
constexpr size_t size() const
1182+
size_t size() const
11661183
{
11671184
return _size;
11681185
}
11691186

1170-
constexpr bool empty() const
1187+
bool empty() const
11711188
{
11721189
return size() == 0;
11731190
}
1174-
explicit constexpr operator bool() const
1191+
explicit operator bool() const
11751192
{
11761193
return !empty();
11771194
}
@@ -1180,23 +1197,24 @@ class Range {
11801197
typename = rapidfuzz::rf_enable_if_t<
11811198
std::is_base_of<std::random_access_iterator_tag,
11821199
typename std::iterator_traits<IterCopy>::iterator_category>::value>>
1183-
constexpr decltype(auto) operator[](size_t n) const
1200+
auto operator[](size_t n) const -> decltype(*_first)
11841201
{
11851202
return _first[static_cast<ptrdiff_t>(n)];
11861203
}
11871204

1188-
constexpr void remove_prefix(size_t n)
1205+
void remove_prefix(size_t n)
11891206
{
11901207
std::advance(_first, static_cast<ptrdiff_t>(n));
11911208
_size -= n;
11921209
}
1193-
constexpr void remove_suffix(size_t n)
1210+
1211+
void remove_suffix(size_t n)
11941212
{
11951213
std::advance(_last, -static_cast<ptrdiff_t>(n));
11961214
_size -= n;
11971215
}
11981216

1199-
constexpr Range subseq(size_t pos = 0, size_t count = std::numeric_limits<size_t>::max())
1217+
Range subseq(size_t pos = 0, size_t count = std::numeric_limits<size_t>::max())
12001218
{
12011219
if (pos > size()) throw std::out_of_range("Index out of range in Range::substr");
12021220

@@ -1207,17 +1225,17 @@ class Range {
12071225
return res;
12081226
}
12091227

1210-
constexpr decltype(auto) front() const
1228+
const value_type& front() const
12111229
{
1212-
return *(_first);
1230+
return *_first;
12131231
}
12141232

1215-
constexpr decltype(auto) back() const
1233+
const value_type& back() const
12161234
{
12171235
return *(_last - 1);
12181236
}
12191237

1220-
constexpr Range<reverse_iterator> reversed() const
1238+
Range<reverse_iterator> reversed() const
12211239
{
12221240
return {rbegin(), rend(), _size};
12231241
}
@@ -1233,16 +1251,15 @@ class Range {
12331251
};
12341252

12351253
template <typename Iter>
1236-
constexpr auto make_range(Iter first, Iter last) -> Range<Iter>
1254+
auto make_range(Iter first, Iter last) -> Range<Iter>
12371255
{
12381256
return Range<Iter>(first, last);
12391257
}
12401258

12411259
template <typename T>
1242-
constexpr auto make_range(T& x) -> Range<decltype(to_begin(x))>
1260+
auto make_range(T& x) -> Range<decltype(to_begin(x))>
12431261
{
1244-
auto first = to_begin(x);
1245-
return Range<decltype(first)>(first, to_end(x));
1262+
return {to_begin(x), to_end(x)};
12461263
}
12471264

12481265
template <typename InputIt1, typename InputIt2>
@@ -1425,7 +1442,7 @@ constexpr uint64_t shl64(uint64_t a, U shift)
14251442
return (shift < 64) ? a << shift : 0;
14261443
}
14271444

1428-
constexpr uint64_t addc64(uint64_t a, uint64_t b, uint64_t carryin, uint64_t* carryout)
1445+
RAPIDFUZZ_CONSTEXPR_CXX14 uint64_t addc64(uint64_t a, uint64_t b, uint64_t carryin, uint64_t* carryout)
14291446
{
14301447
/* todo should use _addcarry_u64 when available */
14311448
a += carryin;
@@ -1436,7 +1453,7 @@ constexpr uint64_t addc64(uint64_t a, uint64_t b, uint64_t carryin, uint64_t* ca
14361453
}
14371454

14381455
template <typename T, typename U>
1439-
constexpr T ceil_div(T a, U divisor)
1456+
RAPIDFUZZ_CONSTEXPR_CXX14 T ceil_div(T a, U divisor)
14401457
{
14411458
T _div = static_cast<T>(divisor);
14421459
return a / _div + static_cast<T>(a % _div != 0);
@@ -1472,7 +1489,7 @@ static inline size_t popcount(uint8_t x)
14721489
}
14731490

14741491
template <typename T>
1475-
constexpr T rotl(T x, unsigned int n)
1492+
RAPIDFUZZ_CONSTEXPR_CXX14 T rotl(T x, unsigned int n)
14761493
{
14771494
unsigned int num_bits = std::numeric_limits<T>::digits;
14781495
assert(n < num_bits);
@@ -1723,6 +1740,15 @@ DecomposedSet<InputIt1, InputIt2, InputIt1> set_decomposition(SplittedSentenceVi
17231740
return {difference_ab, difference_ba, intersection};
17241741
}
17251742

1743+
template <class InputIt1, class InputIt2>
1744+
std::pair<InputIt1, InputIt2> mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
1745+
{
1746+
while (first1 != last1 && first2 != last2 && *first1 == *first2)
1747+
++first1, ++first2;
1748+
1749+
return std::make_pair(first1, first2);
1750+
}
1751+
17261752
/**
17271753
* Removes common prefix of two string views
17281754
*/
@@ -1731,7 +1757,7 @@ size_t remove_common_prefix(Range<InputIt1>& s1, Range<InputIt2>& s2)
17311757
{
17321758
auto first1 = std::begin(s1);
17331759
size_t prefix = static_cast<size_t>(
1734-
std::distance(first1, std::mismatch(first1, std::end(s1), std::begin(s2), std::end(s2)).first));
1760+
std::distance(first1, mismatch(first1, std::end(s1), std::begin(s2), std::end(s2)).first));
17351761
s1.remove_prefix(prefix);
17361762
s2.remove_prefix(prefix);
17371763
return prefix;
@@ -1745,7 +1771,7 @@ size_t remove_common_suffix(Range<InputIt1>& s1, Range<InputIt2>& s2)
17451771
{
17461772
auto rfirst1 = s1.rbegin();
17471773
size_t suffix = static_cast<size_t>(
1748-
std::distance(rfirst1, std::mismatch(rfirst1, s1.rend(), s2.rbegin(), s2.rend()).first));
1774+
std::distance(rfirst1, mismatch(rfirst1, s1.rend(), s2.rbegin(), s2.rend()).first));
17491775
s1.remove_suffix(suffix);
17501776
s2.remove_suffix(suffix);
17511777
return suffix;
@@ -5903,6 +5929,11 @@ struct JaroSimilaritySimdBounds {
59035929

59045930
template <typename VecType, typename InputIt, int _lto_hack = RAPIDFUZZ_LTO_HACK>
59055931
static inline auto jaro_similarity_prepare_bound_short_s2(const VecType* s1_lengths, Range<InputIt>& s2)
5932+
# ifdef RAPIDFUZZ_AVX2
5933+
-> JaroSimilaritySimdBounds<simd_avx2::native_simd<VecType>>
5934+
# else
5935+
-> JaroSimilaritySimdBounds<simd_sse2::native_simd<VecType>>
5936+
# endif
59065937
{
59075938
# ifdef RAPIDFUZZ_AVX2
59085939
using namespace simd_avx2;
@@ -5970,6 +6001,11 @@ static inline auto jaro_similarity_prepare_bound_short_s2(const VecType* s1_leng
59706001

59716002
template <typename VecType, typename InputIt, int _lto_hack = RAPIDFUZZ_LTO_HACK>
59726003
static inline auto jaro_similarity_prepare_bound_long_s2(const VecType* s1_lengths, Range<InputIt>& s2)
6004+
# ifdef RAPIDFUZZ_AVX2
6005+
-> JaroSimilaritySimdBounds<simd_avx2::native_simd<VecType>>
6006+
# else
6007+
-> JaroSimilaritySimdBounds<simd_sse2::native_simd<VecType>>
6008+
# endif
59736009
{
59746010
# ifdef RAPIDFUZZ_AVX2
59756011
using namespace simd_avx2;
@@ -6354,7 +6390,7 @@ struct MultiJaro : public detail::MultiSimilarityBase<MultiJaro<MaxLen>, double,
63546390
friend detail::MultiSimilarityBase<MultiJaro<MaxLen>, double, 0, 1>;
63556391
friend detail::MultiNormalizedMetricBase<MultiJaro<MaxLen>, double>;
63566392

6357-
static_assert(MaxLen == 8 || MaxLen == 16 || MaxLen == 32 || MaxLen == 64);
6393+
static_assert(MaxLen == 8 || MaxLen == 16 || MaxLen == 32 || MaxLen == 64, "incorrect MaxLen used");
63586394

63596395
using VecType = typename std::conditional<
63606396
MaxLen == 8, uint8_t,
@@ -10415,7 +10451,7 @@ double CachedRatio<CharT1>::similarity(const Sentence2& s2, double score_cutoff,
1041510451

1041610452
namespace fuzz_detail {
1041710453

10418-
static constexpr double norm_distance(size_t dist, size_t lensum, double score_cutoff = 0)
10454+
static RAPIDFUZZ_CONSTEXPR_CXX14 double norm_distance(size_t dist, size_t lensum, double score_cutoff = 0)
1041910455
{
1042010456
double score =
1042110457
(lensum > 0) ? (100.0 - 100.0 * static_cast<double>(dist) / static_cast<double>(lensum)) : 100.0;

fuzzing/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function(create_fuzzer fuzzer)
22
add_executable(fuzz_${fuzzer} fuzz_${fuzzer}.cpp)
3-
target_compile_features(fuzz_${fuzzer} PUBLIC cxx_std_14)
3+
target_compile_features(fuzz_${fuzzer} PUBLIC cxx_std_11)
44
target_link_libraries(fuzz_${fuzzer} PRIVATE rapidfuzz::rapidfuzz)
55

66
target_compile_options(fuzz_${fuzzer} PRIVATE -g -O1 -fsanitize=fuzzer,address -march=native)

rapidfuzz/details/Matrix.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ struct ShiftedBitMatrix {
177177
return bool(m_matrix[row][col_word] & col_mask);
178178
}
179179

180-
auto operator[](size_t row) noexcept
180+
BitMatrixView<value_type, false> operator[](size_t row) noexcept
181181
{
182182
return m_matrix[row];
183183
}
184184

185-
auto operator[](size_t row) const noexcept
185+
BitMatrixView<value_type, true> operator[](size_t row) const noexcept
186186
{
187187
return m_matrix[row];
188188
}

0 commit comments

Comments
 (0)