mirror of
https://github.com/TomHarte/CLK.git
synced 2024-07-07 23:29:06 +00:00
Tries operator overloading as a workaround.
This commit is contained in:
parent
bc25c52683
commit
12441bddab
@ -145,6 +145,18 @@ template <class T> class WrappedInt {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Flushes the value in @c this. The current value is returned, and the internal value
|
||||||
|
is reset to zero.
|
||||||
|
*/
|
||||||
|
forceinline template <typename Result> Result flush() {
|
||||||
|
// Jiggery pokery here; switching to function overloading avoids
|
||||||
|
// the namespace-level requirement for template specialisation.
|
||||||
|
Result r;
|
||||||
|
static_cast<T *>(this)->fill_flush(r);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
// operator int() is deliberately not provided, to avoid accidental subtitution of
|
// operator int() is deliberately not provided, to avoid accidental subtitution of
|
||||||
// classes that use this template.
|
// classes that use this template.
|
||||||
|
|
||||||
@ -159,14 +171,11 @@ class Cycles: public WrappedInt<Cycles> {
|
|||||||
forceinline constexpr Cycles() noexcept : WrappedInt<Cycles>() {}
|
forceinline constexpr Cycles() noexcept : WrappedInt<Cycles>() {}
|
||||||
forceinline constexpr Cycles(const Cycles &cycles) noexcept : WrappedInt<Cycles>(cycles.length_) {}
|
forceinline constexpr Cycles(const Cycles &cycles) noexcept : WrappedInt<Cycles>(cycles.length_) {}
|
||||||
|
|
||||||
/*!
|
private:
|
||||||
Flushes the value in @c this. The current value is returned, and the internal value
|
friend WrappedInt;
|
||||||
is reset to zero.
|
void fill_flush(Cycles &result) {
|
||||||
*/
|
result.length_ = length_;
|
||||||
template <typename T> T flush() {
|
|
||||||
const T result(*this);
|
|
||||||
length_ = 0;
|
length_ = 0;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -184,22 +193,6 @@ class HalfCycles: public WrappedInt<HalfCycles> {
|
|||||||
return Cycles(length_ >> 1);
|
return Cycles(length_ >> 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
Flushes the value in @c this. The current value is returned, and the internal value
|
|
||||||
is reset to zero.
|
|
||||||
*/
|
|
||||||
template <typename T> T flush() {
|
|
||||||
const T result(*this);
|
|
||||||
length_ = 0;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <> Cycles flush() {
|
|
||||||
const Cycles result(length_ >> 1);
|
|
||||||
length_ &= 1;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Severs from @c this the effect of dividing by @c divisor; @c this will end up with
|
Severs from @c this the effect of dividing by @c divisor; @c this will end up with
|
||||||
the value of @c this modulo @c divisor and @c divided by @c divisor is returned.
|
the value of @c this modulo @c divisor and @c divided by @c divisor is returned.
|
||||||
@ -210,6 +203,18 @@ class HalfCycles: public WrappedInt<HalfCycles> {
|
|||||||
length_ %= half_divisor.length_;
|
length_ %= half_divisor.length_;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend WrappedInt;
|
||||||
|
void fill_flush(Cycles &result) {
|
||||||
|
result = Cycles(length_ >> 1);
|
||||||
|
length_ &= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fill_flush(HalfCycles &result) {
|
||||||
|
result.length_ = length_;
|
||||||
|
length_ = 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create a specialisation of WrappedInt::flush for converting HalfCycles to Cycles
|
// Create a specialisation of WrappedInt::flush for converting HalfCycles to Cycles
|
||||||
|
Loading…
Reference in New Issue
Block a user