RE: [boost] Re: Perfect moving (almost)

One other thing that makes writing base class and derived classes easier is to add this to the ref struct class X { .... private: struct ref { ref (X *rhs) : p (rhs) {} template<class T> // new ref (T *rhs) : p(rhs) {} // compiles if T is derived from X. X *p; }; ..... }; Then in the derived class you can call: class Y : public X { .... Y(ref rhs) : X (rhs.p) // no cast needed to call X::ref , id(++cnt) , owner(true) { .... } .... }; Anyway the more I play with this the better I like it. Yours, -Gary-

"Powell, Gary" <powellg@amazon.com> writes:
One other thing that makes writing base class and derived classes easier is to add this to the ref struct
class X { .... private: struct ref { ref (X *rhs) : p (rhs) {}
template<class T> // new ref (T *rhs) : p(rhs) {} // compiles if T is derived from X.
X *p; };
..... };
Then in the derived class you can call:
class Y : public X {
....
Y(ref rhs) : X (rhs.p) // no cast needed to call X::ref , id(++cnt) , owner(true) { .... }
.... };
Anyway the more I play with this the better I like it.
If Rani is right about the reference binding I'd like to find some way to library-ize this idiom, so your "ref" converting constructor will come in handy. BTW, you don't need the other "ref" constructor anymore. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Powell, Gary