I have a base class that defines a constrained templated conversion operator
struct base {
template
Following trick requires GNU g++, with C++14.
If some_constraints
and different_constraints
are mutually exclusive, you can add using base::operator auto;
in derived
class to make all the conversion operators of base
available.
Example:
struct Base {
protected:
// conversion to pointer types (protected).
template::value>::type>
operator T() const;
};
struct Derived : public Base{
// Make all Base conversion operators public.
using Base::operator auto;
// conversion to default constructible & non-pointer types.
// added an extra typename=void to distinguish from Base template operator.
template::value>::type,typename=void>
operator T() const;
};
Live demo