I need to know if it is possible to solve the following problem (I am
really stuck at it).
Consider the CRTP pattern:
struct Derived
{
....// May contain void operate( double x ) , may not.
};
template<class D>
struct Base : D
{
....// May contain void operate( double x ) , may not.
void set( double x )
{
static_cast<D*>( this )->operate( x );
}
};
D derived;
derived.set( 1.0 );
What I would like to accomplish, is to have derived.set( 1.0 ) behave
EXACTLY as if the set function were defined inside of Derived.
More precisely, I would like to obtain the same "function lookup"
behaviour for "operate" that I would obtain if set were defined inside
Derived, that is: search for operate inside of Derived, and if not
present search for it inside Base, and if not present gives compile
error.
I know I can search for the existence of "operate" in Derived using
SFINAE to decide if I should do the cast or not.
However, this does not solve my problem because what happens in
reality is that "operate" can be defined in another class from which
Derived inherits.
Basically, I need "something like" static_cast that also searches in
the bases of the converted class, and not only in the particular
converted class. Something like *moving the lookup starting point".
This is the key problem that I need to solve to finish a component of
my library.
Thank you very much in advance for any help.
Best Regards
StephQ