mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-23 03:32:32 +00:00
Attempt to make switch sets even more obviously collapsible.
This commit is contained in:
parent
c630f86f33
commit
4e12d5a70a
@ -21,8 +21,8 @@ struct UnitConverter {
|
|||||||
template <int max, typename SequencerT, typename ConverterT = UnitConverter>
|
template <int max, typename SequencerT, typename ConverterT = UnitConverter>
|
||||||
struct Dispatcher {
|
struct Dispatcher {
|
||||||
|
|
||||||
/// Perform @c target.perform<n>() for the input range [start, end]; @c ConverterT()(n) will be applied to
|
/// Perform @c target.perform<n>() for the input range `start <= n < end`;
|
||||||
/// each individual step before it becomes the relevant template argument.
|
/// @c ConverterT()(n) will be applied to each individual step before it becomes the relevant template argument.
|
||||||
void dispatch(SequencerT &target, int start, int end) {
|
void dispatch(SequencerT &target, int start, int end) {
|
||||||
|
|
||||||
// Minor optimisation: do a comparison with end once outside the loop and if it implies so
|
// Minor optimisation: do a comparison with end once outside the loop and if it implies so
|
||||||
@ -45,11 +45,16 @@ private:
|
|||||||
//
|
//
|
||||||
// Sensible choices by the optimiser are assumed.
|
// Sensible choices by the optimiser are assumed.
|
||||||
|
|
||||||
#define index(n) \
|
#define index(n) \
|
||||||
if constexpr (n == max) return; \
|
case n: \
|
||||||
if(use_end && end == n) return; \
|
if constexpr (n <= max) { \
|
||||||
[[fallthrough]]; \
|
if constexpr (n == max) return; \
|
||||||
case n: target.template perform<ConverterT()(n)>();
|
if constexpr (n < max) { \
|
||||||
|
if(use_end && end == n) return; \
|
||||||
|
} \
|
||||||
|
target.template perform<ConverterT()(n)>(); \
|
||||||
|
} \
|
||||||
|
[[fallthrough]];
|
||||||
|
|
||||||
#define index2(n) index(n); index(n+1);
|
#define index2(n) index(n); index(n+1);
|
||||||
#define index4(n) index2(n); index2(n+2);
|
#define index4(n) index2(n); index2(n+2);
|
||||||
|
Loading…
Reference in New Issue
Block a user