|
Boost Users : |
Subject: Re: [Boost-users] Conditional function definition with boost::enable_if
From: Matthieu Brucher (matthieu.brucher_at_[hidden])
Date: 2009-02-11 03:22:47
2009/2/10 Matthias Vallentin <vallentin_at_[hidden]>:
> On Tue, Feb 10, 2009 at 09:34:20PM +0100, Matthieu Brucher wrote:
>> Would it be possible to derive from a class that has this function?
>> This way, the mother class is template, the template argument being
>> the child class (the curiously recursive template pattern). Then, in
>> the mother class, you can define f() and call i(). I don't know how
>> i() would be exactly called, but you get the idea.
>
> Could you substantiate your solution with a short example, I think I
> don't understand which direction you're heading. What I'm trying to
> accomplish and express in code is the following idea:
>
> If you provide a function (i), you get functionality from the parent (f).
>
> Matthias
> --
> Matthias Vallentin
> vallentin_at_[hidden]
> http://matthias.vallentin.cc
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
Something like (not the correct code though):
template<class Child>
struct MyfStruct
{
typename boost::enable_if<has_i<Child>::type, ...>::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
};
Matthieu
-- Information System Engineer, Ph.D. Website: http://matthieu-brucher.developpez.com/ Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn: http://www.linkedin.com/in/matthieubrucher
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net