Skip to content

Commit fcff9f2

Browse files
committed
port loop unrolling to C++14
1 parent c95fe98 commit fcff9f2

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

extras/rapidfuzz_amalgamated.hpp

+22-8
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 01:37:33.201987
4+
// Generated: 2024-12-25 01:42:39.581315
55
// ----------------------------------------------------------
66
// This file is an amalgamation of multiple different files.
77
// You probably shouldn't edit it directly.
@@ -1563,16 +1563,30 @@ static inline unsigned int countr_zero(uint8_t x)
15631563
return countr_zero(static_cast<uint32_t>(x));
15641564
}
15651565

1566-
template <class T, T... inds, class F>
1567-
constexpr void unroll_impl(std::integer_sequence<T, inds...>, F&& f)
1568-
{
1569-
(f(std::integral_constant<T, inds>{}), ...);
1570-
}
1566+
template <typename T, T N, T Pos = 0, bool IsEmpty = (N == 0)>
1567+
struct UnrollImpl;
1568+
1569+
template <typename T, T N, T Pos>
1570+
struct UnrollImpl<T, N, Pos, false> {
1571+
template <typename F>
1572+
static void call(F&& f)
1573+
{
1574+
f(Pos);
1575+
UnrollImpl<T, N - 1, Pos + 1>::call(std::forward<F>(f));
1576+
}
1577+
};
1578+
1579+
template <typename T, T N, T Pos>
1580+
struct UnrollImpl<T, N, Pos, true> {
1581+
template <typename F>
1582+
static void call(F&&)
1583+
{}
1584+
};
15711585

1572-
template <class T, T count, class F>
1586+
template <typename T, int N, class F>
15731587
constexpr void unroll(F&& f)
15741588
{
1575-
unroll_impl(std::make_integer_sequence<T, count>{}, std::forward<F>(f));
1589+
UnrollImpl<T, N>::call(f);
15761590
}
15771591

15781592
} // namespace detail

rapidfuzz/details/intrinsics.hpp

+21-7
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,30 @@ static inline unsigned int countr_zero(uint8_t x)
198198
return countr_zero(static_cast<uint32_t>(x));
199199
}
200200

201-
template <class T, T... inds, class F>
202-
constexpr void unroll_impl(std::integer_sequence<T, inds...>, F&& f)
203-
{
204-
(f(std::integral_constant<T, inds>{}), ...);
205-
}
201+
template <typename T, T N, T Pos = 0, bool IsEmpty = (N == 0)>
202+
struct UnrollImpl;
203+
204+
template <typename T, T N, T Pos>
205+
struct UnrollImpl<T, N, Pos, false> {
206+
template <typename F>
207+
static void call(F&& f)
208+
{
209+
f(Pos);
210+
UnrollImpl<T, N - 1, Pos + 1>::call(std::forward<F>(f));
211+
}
212+
};
213+
214+
template <typename T, T N, T Pos>
215+
struct UnrollImpl<T, N, Pos, true> {
216+
template <typename F>
217+
static void call(F&&)
218+
{}
219+
};
206220

207-
template <class T, T count, class F>
221+
template <typename T, int N, class F>
208222
constexpr void unroll(F&& f)
209223
{
210-
unroll_impl(std::make_integer_sequence<T, count>{}, std::forward<F>(f));
224+
UnrollImpl<T, N>::call(f);
211225
}
212226

213227
} // namespace detail

0 commit comments

Comments
 (0)