|
Boost : |
From: John Max Skaller (skaller_at_[hidden])
Date: 2001-05-21 21:52:59
David Abrahams wrote:
> > That's roughly my understanding too. But now note that
> > the original trick relied on injection: inserting the declaration
> > of a function first declared as a friend inside a class
> > just before the class definition: I don't believe that happens
> > any more. Instead, Koenig lookup is used. That means that
> > the friend needs to have an argument of the class type
> > to be found outside the class.
>
> No, just an argument from the same namespace as the class type.
I assumed that was understood without mentioning it.
> > When you start using templates all hell breaks loose.
> > [The lookup rules appear to be imprecise, incomplete,
> > and/or inadequate; but it is hard to tell]
>
> They're well-defined. No need for FUD here.
I post the example I posted to the
committee reflector, this example doesn't even
involve recursive templates (there is recursion,
but only between ordinary classes).
----------- FAILS UNDER G++ 2.95.3 -------------------
template<class T> struct smart_ptr {
smart_ptr(T *t) { t->incref(); } // INLINE
smart_ptr(){}
};
class X;
class Y;
struct X {
smart_ptr<Y> y;
void incref() {}
X(Y *ya) : y(ya){}
X(){}
};
struct Y {
smart_ptr<X> x;
void incref() {}
Y(X *xa) : x(xa){}
Y(){}
};
//template<class T>
//smart_ptr<T>::smart_ptr<T>(T *t) { t-> incref(); }
void main()
{
X x;
}
----------- WORKS UNDER G++ 2.95.3 --------------------
template<class T> struct smart_ptr {
smart_ptr(T *t); // OUT OF LINE
smart_ptr(){}
};
class X;
class Y;
struct X {
smart_ptr<Y> y;
void incref() {}
X(Y *ya) : y(ya){}
X(){}
};
struct Y {
smart_ptr<X> x;
void incref() {}
Y(X *xa) : x(xa){}
Y(){}
};
template<class T>
smart_ptr<T>::smart_ptr<T>(T *t) { t-> incref(); }
void main()
{
X x;
}
-- John (Max) Skaller, mailto:skaller_at_[hidden] 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850 checkout Vyper http://Vyper.sourceforge.net download Interscript http://Interscript.sourceforge.net
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk