I am trying to prune back combinatorial explosion of specializations by passing const-ness transparently through a template parameter:
template <typename Sig>
struct IFoo { virtual Sig operator() = 0; }; // XXX, but OK with non-templated aliases...
The compilers are treating Sig
as a non-function type before instantiation, so I think I am just looking for a way to coerce the system out of that early belief about the type. Is this not possible, or have I just not stumbled across the correct grammar yet?
I explicitly want to avoid the usual style of specialization-induced deduction:
template <typename Sig> struct IFoo;
template <typename R, typename... Args>
struct IFoo<R(Args...)> { virtual R operator()(Args...) = 0; };
template <typename R, typename... Args>
struct IFoo<R(Args...) const> { virtual R operator()(Args...) const = 0; };
Alternately, is there anything available for const
along the lines of the noexcept
extraction made available in C++17?
template <typename Sig> struct IBar;
template <typename R, typename... Args, bool IsNoExcept>
struct IBar<R(Args...) noexcept(IsNoExcept)> {
virtual R operator()(Args...) noexcept(IsNoExcept) = 0;
};
I am unfortunately stuck in C++14, but AFAIK there is no magic if constexpr
equivalent in C++17 that is usable from within class definition scope anyway.