Skip to content

Commit 369e4d1

Browse files
committed
finish C++14 support
1 parent 4e928a1 commit 369e4d1

26 files changed

+335
-307
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
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_11)
53+
target_compile_features(rapidfuzz INTERFACE cxx_std_14)
5454

5555
target_include_directories(rapidfuzz
5656
INTERFACE

extras/rapidfuzz_amalgamated.hpp

Lines changed: 103 additions & 89 deletions
Large diffs are not rendered by default.

fuzzing/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
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_11)
3+
target_compile_features(fuzz_${fuzzer} PUBLIC cxx_std_14)
44
target_link_libraries(fuzz_${fuzzer} PRIVATE rapidfuzz::rapidfuzz)
55

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

fuzzing/fuzz_levenshtein_editops.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
3030
validate_editops(s1, s2, score, score);
3131

3232
if (s1.size() > 1 && s2.size() > 1) {
33-
auto hpos = rapidfuzz::detail::find_hirschberg_pos(rapidfuzz::detail::Range(s1),
34-
rapidfuzz::detail::Range(s2));
33+
auto hpos = rapidfuzz::detail::find_hirschberg_pos(rapidfuzz::detail::make_range(s1),
34+
rapidfuzz::detail::make_range(s2));
3535
if (hpos.left_score + hpos.right_score != score)
3636
throw std::logic_error("find_hirschberg_pos failed");
3737
}

rapidfuzz/details/Range.hpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,8 @@ class Range {
8282
{}
8383

8484
template <typename T>
85-
constexpr Range(T& x) : _first(to_begin(x)), _last(to_end(x))
86-
{
87-
assert(std::distance(_first, _last) >= 0);
88-
_size = static_cast<size_t>(std::distance(_first, _last));
89-
}
85+
constexpr Range(T& x) : Range(to_begin(x), to_end(x))
86+
{}
9087

9188
constexpr iterator begin() const noexcept
9289
{
@@ -176,8 +173,18 @@ class Range {
176173
}
177174
};
178175

176+
template <typename Iter>
177+
constexpr auto make_range(Iter first, Iter last) -> Range<Iter>
178+
{
179+
return Range<Iter>(first, last);
180+
}
181+
179182
template <typename T>
180-
Range(T& x) -> Range<decltype(to_begin(x))>;
183+
constexpr auto make_range(T& x) -> Range<decltype(to_begin(x))>
184+
{
185+
auto first = to_begin(x);
186+
return Range<decltype(first)>(first, to_end(x));
187+
}
181188

182189
template <typename InputIt1, typename InputIt2>
183190
inline bool operator==(const Range<InputIt1>& a, const Range<InputIt2>& b)

rapidfuzz/details/distance.hpp

Lines changed: 56 additions & 52 deletions
Large diffs are not rendered by default.

rapidfuzz/details/type_traits.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct is_explicitly_convertible {
4949
static bool const value = test<From, To>(0);
5050
};
5151

52-
template<bool B, class T = void>
52+
template <bool B, class T = void>
5353
using rf_enable_if_t = typename std::enable_if<B, T>::type;
5454

5555
} // namespace rapidfuzz

rapidfuzz/distance/Hamming.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ template <typename InputIt1, typename InputIt2>
7878
Editops hamming_editops(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, bool pad_ = true,
7979
size_t score_hint = std::numeric_limits<size_t>::max())
8080
{
81-
return detail::hamming_editops(detail::Range(first1, last1), detail::Range(first2, last2), pad_,
81+
return detail::hamming_editops(detail::make_range(first1, last1), detail::make_range(first2, last2), pad_,
8282
score_hint);
8383
}
8484

8585
template <typename Sentence1, typename Sentence2>
8686
Editops hamming_editops(const Sentence1& s1, const Sentence2& s2, bool pad_ = true,
8787
size_t score_hint = std::numeric_limits<size_t>::max())
8888
{
89-
return detail::hamming_editops(detail::Range(s1), detail::Range(s2), pad_, score_hint);
89+
return detail::hamming_editops(detail::make_range(s1), detail::make_range(s2), pad_, score_hint);
9090
}
9191

9292
/**

rapidfuzz/distance/Jaro.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ struct MultiJaro : public detail::MultiSimilarityBase<MultiJaro<MaxLen>, double,
7070
friend detail::MultiSimilarityBase<MultiJaro<MaxLen>, double, 0, 1>;
7171
friend detail::MultiNormalizedMetricBase<MultiJaro<MaxLen>, double>;
7272

73-
static_assert(MaxLen == 8 || MaxLen == 16 || MaxLen == 32 || MaxLen == 64);
73+
static_assert(MaxLen == 8 || MaxLen == 16 || MaxLen == 32 || MaxLen == 64, "incorrect MaxLen used");
7474

7575
using VecType = typename std::conditional<
7676
MaxLen == 8, uint8_t,
7777
typename std::conditional<MaxLen == 16, uint16_t,
78-
typename std::conditional<MaxLen == 32, uint32_t, uint64_t>::type>::type>::type;
78+
typename std::conditional<MaxLen == 32, uint32_t, uint64_t>::type>::type>::
79+
type;
7980

8081
constexpr static size_t get_vec_size()
8182
{
@@ -166,7 +167,7 @@ struct MultiJaro : public detail::MultiSimilarityBase<MultiJaro<MaxLen>, double,
166167
if (score_count < result_count())
167168
throw std::invalid_argument("scores has to have >= result_count() elements");
168169

169-
detail::Range scores_(scores, scores + score_count);
170+
auto scores_ = detail::make_range(scores, scores + score_count);
170171
detail::jaro_similarity_simd<VecType>(scores_, PM, str_lens, str_lens_size, s2, score_cutoff);
171172
}
172173

@@ -198,7 +199,7 @@ struct CachedJaro : public detail::CachedSimilarityBase<CachedJaro<CharT1>, doub
198199
{}
199200

200201
template <typename InputIt1>
201-
CachedJaro(InputIt1 first1, InputIt1 last1) : s1(first1, last1), PM(detail::Range(first1, last1))
202+
CachedJaro(InputIt1 first1, InputIt1 last1) : s1(first1, last1), PM(detail::make_range(first1, last1))
202203
{}
203204

204205
private:
@@ -215,7 +216,7 @@ struct CachedJaro : public detail::CachedSimilarityBase<CachedJaro<CharT1>, doub
215216
double _similarity(const detail::Range<InputIt2>& s2, double score_cutoff,
216217
[[maybe_unused]] double score_hint) const
217218
{
218-
return detail::jaro_similarity(PM, detail::Range(s1), s2, score_cutoff);
219+
return detail::jaro_similarity(PM, detail::make_range(s1), s2, score_cutoff);
219220
}
220221

221222
std::vector<CharT1> s1;

rapidfuzz/distance/JaroWinkler.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ struct CachedJaroWinkler : public detail::CachedSimilarityBase<CachedJaroWinkler
174174

175175
template <typename InputIt1>
176176
CachedJaroWinkler(InputIt1 first1, InputIt1 last1, double _prefix_weight = 0.1)
177-
: prefix_weight(_prefix_weight), s1(first1, last1), PM(detail::Range(first1, last1))
177+
: prefix_weight(_prefix_weight), s1(first1, last1), PM(detail::make_range(first1, last1))
178178
{}
179179

180180
private:
@@ -191,7 +191,7 @@ struct CachedJaroWinkler : public detail::CachedSimilarityBase<CachedJaroWinkler
191191
double _similarity(const detail::Range<InputIt2>& s2, double score_cutoff,
192192
[[maybe_unused]] double score_hint) const
193193
{
194-
return detail::jaro_winkler_similarity(PM, detail::Range(s1), s2, prefix_weight, score_cutoff);
194+
return detail::jaro_winkler_similarity(PM, detail::make_range(s1), s2, prefix_weight, score_cutoff);
195195
}
196196

197197
double prefix_weight;

0 commit comments

Comments
 (0)