My program has a meta object that takes a strategy at compile time. The strategy may either implement the method begin()
or have it marked as delete
'd.
In the implementation, I now want to branch on exactly this condition and roll my own implementation of begin()
in the case where the strategy doesn't provide one.
Is this somehow possible?
Here's what I want:
#include <cstdio>
struct implA
{
auto begin() { return start; }
void* start;
};
struct implB
{
auto begin() = delete;
};
template <typename Impl>
struct meta
{
auto begin() {
if constexpr (/* implementation available... */) {
// ... use it
return impl_.begin;
} else {
// ... roll our own
return start;
}
}
void* start;
Impl impl_;
};
int main()
{
meta<implA> m;
meta<implB> m;
}