On Wed, 5 Oct 2005, Geoffrey Irving wrote:
Hello,
Is it possible to get boost::operator like functionality for general methods? In other words, I'd like to be able to do the following:
template<...> struct complete : public ... { void f(){a();} void g(); };
struct C : public complete<...> { void a(); void b(){g();} };
The resulting class C would have methods a,b,g,f. Here C::b refers to the complete::g and complete::f refers to C::a, so the dependencies are circular. It seems like the boost::operators setup can handle this kind of circular dependency, but I'm not how to do it for methods.
I am doing that for implementing some vector operations (I mean, math vectors), e.g. normalization, negation, swap, etc. I need this circular dependency to access the bracket operator. But you can do the same for anything else. In your case, you could do something like: struct empty_base {} ; template < typename Derived , class Base = empty_base > struct complete : Base // if you want to chain operations as in Boost.Operators { void f() { static_cast< Derived* >( this )->a() ; } void g() { /*...*/ } } ; struct C : complete< C > { private : typedef complete< C > base_type_ ; public : void a() { /*...*/ } void b() { base_type_::g() ; } } ; -- Francois