Skip to content

Commit c95fe98

Browse files
committed
improve support for C++11
1 parent 93603d5 commit c95fe98

26 files changed

+233
-145
lines changed

extras/rapidfuzz_amalgamated.hpp

Lines changed: 116 additions & 72 deletions
Large diffs are not rendered by default.

rapidfuzz/details/CharSet.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
#include <type_traits>
1010
#include <unordered_set>
1111

12-
namespace rapidfuzz::detail {
12+
namespace rapidfuzz {
13+
namespace detail {
1314

1415
/*
1516
* taken from https://stackoverflow.com/a/17251989/11335032
@@ -71,4 +72,5 @@ struct CharSet {
7172
}
7273
};
7374

74-
} // namespace rapidfuzz::detail
75+
} // namespace detail
76+
} // namespace rapidfuzz

rapidfuzz/details/GrowingHashmap.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include <stddef.h>
88
#include <stdint.h>
99

10-
namespace rapidfuzz::detail {
10+
namespace rapidfuzz {
11+
namespace detail {
1112

1213
/* hashmap for integers which can only grow, but can't remove elements */
1314
template <typename T_Key, typename T_Entry>
@@ -200,4 +201,5 @@ struct HybridGrowingHashmap {
200201
std::array<value_type, 256> m_extendedAscii;
201202
};
202203

203-
} // namespace rapidfuzz::detail
204+
} // namespace detail
205+
} // namespace rapidfuzz

rapidfuzz/details/Matrix.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#include <stdio.h>
99
#include <vector>
1010

11-
namespace rapidfuzz::detail {
11+
namespace rapidfuzz {
12+
namespace detail {
1213

1314
template <typename T, bool IsConst>
1415
struct BitMatrixView {
@@ -196,4 +197,5 @@ struct ShiftedBitMatrix {
196197
std::vector<ptrdiff_t> m_offsets;
197198
};
198199

199-
} // namespace rapidfuzz::detail
200+
} // namespace detail
201+
} // namespace rapidfuzz

rapidfuzz/details/PatternMatchVector.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
#include <rapidfuzz/details/Range.hpp>
1212
#include <rapidfuzz/details/intrinsics.hpp>
1313

14-
namespace rapidfuzz::detail {
14+
namespace rapidfuzz {
15+
namespace detail {
1516

1617
struct BitvectorHashmap {
1718
BitvectorHashmap() : m_map()
@@ -219,4 +220,5 @@ struct BlockPatternMatchVector {
219220
BitMatrix<uint64_t> m_extendedAscii;
220221
};
221222

222-
} // namespace rapidfuzz::detail
223+
} // namespace detail
224+
} // namespace rapidfuzz

rapidfuzz/details/Range.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#include <sys/types.h>
1414
#include <vector>
1515

16-
namespace rapidfuzz::detail {
16+
namespace rapidfuzz {
17+
namespace detail {
1718

1819
static inline void assume(bool b)
1920
{
@@ -117,10 +118,10 @@ class Range {
117118
return !empty();
118119
}
119120

120-
template <
121-
typename... Dummy, typename IterCopy = Iter,
122-
typename = std::enable_if_t<std::is_base_of_v<
123-
std::random_access_iterator_tag, typename std::iterator_traits<IterCopy>::iterator_category>>>
121+
template <typename... Dummy, typename IterCopy = Iter,
122+
typename = std::enable_if_t<
123+
std::is_base_of<std::random_access_iterator_tag,
124+
typename std::iterator_traits<IterCopy>::iterator_category>::value>>
124125
constexpr decltype(auto) operator[](size_t n) const
125126
{
126127
return _first[static_cast<ptrdiff_t>(n)];
@@ -215,4 +216,5 @@ inline bool operator>=(const Range<InputIt1>& a, const Range<InputIt2>& b)
215216
template <typename InputIt>
216217
using RangeVec = std::vector<Range<InputIt>>;
217218

218-
} // namespace rapidfuzz::detail
219+
} // namespace detail
220+
} // namespace rapidfuzz

rapidfuzz/details/SplittedSentenceView.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
#include <rapidfuzz/details/Range.hpp>
44
#include <rapidfuzz/details/type_traits.hpp>
55

6-
namespace rapidfuzz::detail {
6+
namespace rapidfuzz {
7+
namespace detail {
78

89
template <typename InputIt>
910
class SplittedSentenceView {
1011
public:
1112
using CharT = iter_value_t<InputIt>;
1213

1314
SplittedSentenceView(RangeVec<InputIt> sentence) noexcept(
14-
std::is_nothrow_move_constructible_v<RangeVec<InputIt>>)
15+
std::is_nothrow_move_constructible<RangeVec<InputIt>>::value)
1516
: m_sentence(std::move(sentence))
1617
{}
1718

@@ -83,4 +84,5 @@ auto SplittedSentenceView<InputIt>::join() const -> std::vector<CharT>
8384
return joined;
8485
}
8586

86-
} // namespace rapidfuzz::detail
87+
} // namespace detail
88+
} // namespace rapidfuzz

rapidfuzz/details/common.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
# include <mm_malloc.h>
1414
#endif
1515

16-
namespace rapidfuzz::detail {
16+
namespace rapidfuzz {
17+
namespace detail {
1718

1819
template <typename InputIt1, typename InputIt2, typename InputIt3>
1920
struct DecomposedSet {
@@ -94,6 +95,7 @@ static inline void rf_aligned_free(void* ptr)
9495

9596
/**@}*/
9697

97-
} // namespace rapidfuzz::detail
98+
} // namespace detail
99+
} // namespace rapidfuzz
98100

99101
#include <rapidfuzz/details/common_impl.hpp>

rapidfuzz/details/common_impl.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#include <array>
66
#include <iterator>
77

8-
namespace rapidfuzz::detail {
8+
namespace rapidfuzz {
9+
namespace detail {
910

1011
template <typename InputIt1, typename InputIt2>
1112
DecomposedSet<InputIt1, InputIt2, InputIt1> set_decomposition(SplittedSentenceView<InputIt1> a,
@@ -169,4 +170,5 @@ SplittedSentenceView<InputIt> sorted_split(InputIt first, InputIt last)
169170
return SplittedSentenceView<InputIt>(splitted);
170171
}
171172

172-
} // namespace rapidfuzz::detail
173+
} // namespace detail
174+
} // namespace rapidfuzz

rapidfuzz/details/distance.hpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
#include <rapidfuzz/details/simd.hpp>
1010
#include <type_traits>
1111

12-
namespace rapidfuzz::detail {
12+
namespace rapidfuzz {
13+
namespace detail {
1314

1415
template <typename T, typename... Args>
1516
struct NormalizedMetricBase {
1617
template <typename InputIt1, typename InputIt2,
17-
typename = std::enable_if_t<!std::is_same_v<InputIt2, double>>>
18+
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
1819
static double normalized_distance(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2,
1920
Args... args, double score_cutoff, double score_hint)
2021
{
@@ -31,7 +32,7 @@ struct NormalizedMetricBase {
3132
}
3233

3334
template <typename InputIt1, typename InputIt2,
34-
typename = std::enable_if_t<!std::is_same_v<InputIt2, double>>>
35+
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
3536
static double normalized_similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2,
3637
Args... args, double score_cutoff, double score_hint)
3738
{
@@ -82,7 +83,7 @@ struct NormalizedMetricBase {
8283
template <typename T, typename ResType, int64_t WorstSimilarity, int64_t WorstDistance, typename... Args>
8384
struct DistanceBase : public NormalizedMetricBase<T, Args...> {
8485
template <typename InputIt1, typename InputIt2,
85-
typename = std::enable_if_t<!std::is_same_v<InputIt2, double>>>
86+
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
8687
static ResType distance(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
8788
ResType score_cutoff, ResType score_hint)
8889
{
@@ -98,7 +99,7 @@ struct DistanceBase : public NormalizedMetricBase<T, Args...> {
9899
}
99100

100101
template <typename InputIt1, typename InputIt2,
101-
typename = std::enable_if_t<!std::is_same_v<InputIt2, double>>>
102+
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
102103
static ResType similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
103104
ResType score_cutoff, ResType score_hint)
104105
{
@@ -137,7 +138,7 @@ struct DistanceBase : public NormalizedMetricBase<T, Args...> {
137138
template <typename T, typename ResType, int64_t WorstSimilarity, int64_t WorstDistance, typename... Args>
138139
struct SimilarityBase : public NormalizedMetricBase<T, Args...> {
139140
template <typename InputIt1, typename InputIt2,
140-
typename = std::enable_if_t<!std::is_same_v<InputIt2, double>>>
141+
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
141142
static ResType distance(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
142143
ResType score_cutoff, ResType score_hint)
143144
{
@@ -153,7 +154,7 @@ struct SimilarityBase : public NormalizedMetricBase<T, Args...> {
153154
}
154155

155156
template <typename InputIt1, typename InputIt2,
156-
typename = std::enable_if_t<!std::is_same_v<InputIt2, double>>>
157+
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
157158
static ResType similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
158159
ResType score_cutoff, ResType score_hint)
159160
{
@@ -184,15 +185,15 @@ struct SimilarityBase : public NormalizedMetricBase<T, Args...> {
184185
}
185186

186187
template <typename U>
187-
static std::enable_if_t<std::is_floating_point_v<U>, U> _apply_distance_score_cutoff(U score,
188-
U score_cutoff)
188+
static std::enable_if_t<std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
189+
U score_cutoff)
189190
{
190191
return (score <= score_cutoff) ? score : 1.0;
191192
}
192193

193194
template <typename U>
194-
static std::enable_if_t<!std::is_floating_point_v<U>, U> _apply_distance_score_cutoff(U score,
195-
U score_cutoff)
195+
static std::enable_if_t<!std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
196+
U score_cutoff)
196197
{
197198
return (score <= score_cutoff) ? score : score_cutoff + 1;
198199
}
@@ -364,15 +365,15 @@ struct CachedSimilarityBase : public CachedNormalizedMetricBase<T> {
364365
}
365366

366367
template <typename U>
367-
static std::enable_if_t<std::is_floating_point_v<U>, U> _apply_distance_score_cutoff(U score,
368-
U score_cutoff)
368+
static std::enable_if_t<std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
369+
U score_cutoff)
369370
{
370371
return (score <= score_cutoff) ? score : 1.0;
371372
}
372373

373374
template <typename U>
374-
static std::enable_if_t<!std::is_floating_point_v<U>, U> _apply_distance_score_cutoff(U score,
375-
U score_cutoff)
375+
static std::enable_if_t<!std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
376+
U score_cutoff)
376377
{
377378
return (score <= score_cutoff) ? score : score_cutoff + 1;
378379
}
@@ -558,15 +559,15 @@ struct MultiSimilarityBase : public MultiNormalizedMetricBase<T, ResType> {
558559
}
559560

560561
template <typename U>
561-
static std::enable_if_t<std::is_floating_point_v<U>, U> _apply_distance_score_cutoff(U score,
562-
U score_cutoff)
562+
static std::enable_if_t<std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
563+
U score_cutoff)
563564
{
564565
return (score <= score_cutoff) ? score : 1.0;
565566
}
566567

567568
template <typename U>
568-
static std::enable_if_t<!std::is_floating_point_v<U>, U> _apply_distance_score_cutoff(U score,
569-
U score_cutoff)
569+
static std::enable_if_t<!std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
570+
U score_cutoff)
570571
{
571572
return (score <= score_cutoff) ? score : score_cutoff + 1;
572573
}
@@ -576,4 +577,5 @@ struct MultiSimilarityBase : public MultiNormalizedMetricBase<T, ResType> {
576577
friend T;
577578
};
578579

579-
} // namespace rapidfuzz::detail
580+
} // namespace detail
581+
} // namespace rapidfuzz

rapidfuzz/details/intrinsics.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
# include <intrin.h>
1515
#endif
1616

17-
namespace rapidfuzz::detail {
17+
namespace rapidfuzz {
18+
namespace detail {
1819

1920
template <typename T>
2021
T bit_mask_lsb(size_t n)
@@ -209,4 +210,5 @@ constexpr void unroll(F&& f)
209210
unroll_impl(std::make_integer_sequence<T, count>{}, std::forward<F>(f));
210211
}
211212

212-
} // namespace rapidfuzz::detail
213+
} // namespace detail
214+
} // namespace rapidfuzz

rapidfuzz/distance/DamerauLevenshtein_impl.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
#include <rapidfuzz/details/common.hpp>
1212
#include <rapidfuzz/details/distance.hpp>
1313

14-
namespace rapidfuzz::detail {
14+
namespace rapidfuzz {
15+
namespace detail {
1516

1617
template <typename IntType>
1718
struct RowId {
@@ -137,4 +138,5 @@ class DamerauLevenshtein
137138
}
138139
};
139140

140-
} // namespace rapidfuzz::detail
141+
} // namespace detail
142+
} // namespace rapidfuzz

rapidfuzz/distance/Hamming_impl.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#include <rapidfuzz/details/distance.hpp>
77
#include <stdexcept>
88

9-
namespace rapidfuzz::detail {
9+
namespace rapidfuzz {
10+
namespace detail {
1011

1112
class Hamming : public DistanceBase<Hamming, size_t, 0, std::numeric_limits<int64_t>::max(), bool> {
1213
friend DistanceBase<Hamming, size_t, 0, std::numeric_limits<int64_t>::max(), bool>;
@@ -57,4 +58,5 @@ Editops hamming_editops(const Range<InputIt1>& s1, const Range<InputIt2>& s2, bo
5758
return ops;
5859
}
5960

60-
} // namespace rapidfuzz::detail
61+
} // namespace detail
62+
} // namespace rapidfuzz

rapidfuzz/distance/Indel_impl.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#include <rapidfuzz/details/intrinsics.hpp>
99
#include <rapidfuzz/distance/LCSseq.hpp>
1010

11-
namespace rapidfuzz::detail {
11+
namespace rapidfuzz {
12+
namespace detail {
1213

1314
template <typename InputIt1, typename InputIt2>
1415
size_t indel_distance(const BlockPatternMatchVector& block, const Range<InputIt1>& s1,
@@ -65,4 +66,5 @@ class Indel : public DistanceBase<Indel, size_t, 0, std::numeric_limits<int64_t>
6566
}
6667
};
6768

68-
} // namespace rapidfuzz::detail
69+
} // namespace detail
70+
} // namespace rapidfuzz

0 commit comments

Comments
 (0)