Re: [Boost-users] multi-inheritance from elements of mpl::vector?==> inherit_scattered ( for Barton & Nackmann trick)
no reply - so I found a solution by myself (used for the Barton & Nackmann trick)! template< typename D > struct F { std::string f() { return static_cast< D & >( * this).str_; } };
template< typename D > struct G { std::string g() { return static_cast< D & >( * this).str_; } };
That's not the B&N trick; it's simple CRTP. The B&N trick is the one where you stick a friend function that applies to the derived class in the base class. See the operators library for reference.
Sorry - in your book (C++ Template Metaprogramming, page 205) I can read: "The technique of using a static_cast with CRTP to reach the derived object is sometimes called the "Barton and Nackmann trick" ...". Is this wrong? So long, Oliver
--- Oliver Kowalke wrote:
Sorry - in your book (C++ Template Metaprogramming, page 205) I can read: "The technique of using a static_cast with CRTP to reach the derived object is sometimes called the "Barton and Nackmann trick" ...". Is this wrong?
In "C++ Templates" by David Vandevoorde and Nicolai M. Josuttis, bottom of page 299: "CRTP is also sometimes confused with the Barton-Nackman trick because Barton and Nackman frequently used CRTP in combination with friend name injection (and the latter is an important component of the Barton-Nackman trick)." Cromwell D. Enage __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com
no reply - so I found a solution by myself (used for the Barton & Nackmann trick)! template< typename D > struct F { std::string f() { return static_cast< D & >( * this).str_; } };
template< typename D > struct G { std::string g() { return static_cast< D & >( * this).str_; } };
That's not the B&N trick; it's simple CRTP. The B&N trick is the one where you stick a friend function that applies to the derived class in the base class. See the operators library for reference.
Sorry - in your book (C++ Template Metaprogramming, page 205) I can read: "The technique of using a static_cast with CRTP to reach the derived object is sometimes called the "Barton and Nackmann trick" ...". Is this wrong?
No, I guess you're right; if you read the Wikipedia definition I cited, you'll see: Today the Barton-Nackman trick has become synonymous with "curiously recurring templates" (a term due to Coplien [4], but which Barton and Nackman popularized), in which a base class template is instantiated with a derived class type as its template parameter... Sorry about the noise. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (3)
-
Cromwell Enage
-
David Abrahams
-
Oliver.Kowalke@infineon.com