Hi Matthieu, On Wed, Feb 11, 2009 at 09:22:47AM +0100, Matthieu Brucher wrote:
template<class Child> struct MyfStruct { typename boost::enable_if
::type f() { // Do some stuff, but I don't know how to call i(), you will have to test :| } }; where has_i<> tests if the child has the method i().
Then, if you find how to call i() from the f() method, you just have to write:
class MyClass: public MyfStruct<MyClass> { void i(); // f() will be callable now };
Thanks for your example. Yet I believe, that the solution you propose does
not solve the underlying problem: as the compiler errors indicate,
struct bar (or in your example, class MyClass) is incomplete at the time
when has_i<Child> [*] is called. Hence, bar/MyClass cannot use CRTP to
automatically derive functions from foo/MyfStruct. I will have to use a
different approach to inject functions conditionally.
Matthias
[*] This would factor out the code that checks whether T has i():
template <typename T>
struct has_i
: boost::mpl::bool_