Is there a way in which I can test that the Derived
class is derived from BaseInterface
where the template parameters for the BaseInterface
are unsigned integral values?
I'm wanting to perform this check as part of a template std::enable_if.
The BaseInterface
has a method that takes in a reference to a block of bytes, of which that block will have a fixed size depending upon the OutputSize
template parameter.
template < size_t BlockSize, size_t OutputSize >
class BaseInterface {
public:
const static size_t BLOCK_SIZE = BlockSize;
const static size_t OUTPUT_SIZE = OutputSize;
using Output = uint8_t[ OutputSize ];
virtual ~BaseInterface() = default;
virtual void update( uint8_t*, size_t ) = 0;
virtual void getOutput( Output& ) = 0;
};
class Derived : public BaseInterface< 64, 16 > {
public:
...
};
I've seen a comment mentioning that this could be done, but it would be more complicated than the usual std::is_base_of or std::derived_from. Of course, I've not been able to find any instance of this "more complicated way".
Because the template parameters are not types, but instead unsigned integral values, neither of these work. I guess what I'm mostly interested in is whether the interface is present in the class passed in via the template. I could always just check for every method, typedef and constant. That might get annoying... So if there's a better way of doing this feel free to speak up.
template < typename ImplementedInterface,
typename = typename std::enable_if<
... other checks here ...
is_derived< Derived, Base ??? >
>::type >
void method( ... input here ... ) {
ImplementedInterface ii;
ImplementedInterface::Output out;
ii.update( ... );
ii.output( out );
}
In the mean time, I'll be figuring out how much work it would be to check the derived class for the required interface.