[boost] Re: intrusive tagging allows omision of unneeded headers
Thorsten Ottosen wrote: - Original Message - From: "Dirk Gerrits" <[EMAIL PROTECTED]> To: "Boost mailing list" <[EMAIL PROTECTED]> Sent: Wednesday, January 08, 2003 6:15 PM Subject: [boost] Re: intrusive tagging allows omision of unneeded headers Thorsten Ottosen wrote: [snip] class X { public: class tag {}; typedef tag X_tag; ^ }; class bar { public: class tag {}; typedef tag bar_tag; ^^^ }; Why these typedefs? Why would one write X::X_tag instead of X::tag for example? how can we specifiy that we want to specialize for a particular class otherwise? Only by establising a convetion that all (involved) classes have a unique typedef can we destinguish the classes. For example template< typename C > void foo_impl( const C& c, typename C::bar_tag ) { cout << "bar specialised version" << endl; } will only be a candidate when C actually has a typedef bar_tag. due to SFINAE the instantiation is allowed to fail for classes that does not have a bar_tag typdef. And because the above foo_impl is more specialized than template< typename C, typename Tag > void foo_impl( const C& c, Tag t ) { cout << "default version" << endl; } the first foo_impl will be chosen as a better match. Ahh, I guess I didn't fully understand everything that was going on. This makes sense. Thanks! Dirk Gerrits ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Re: [boost] Re: intrusive tagging allows omision of unneeded headers
- Original Message - From: "Dirk Gerrits" <[EMAIL PROTECTED]> To: "Boost mailing list" <[EMAIL PROTECTED]> Sent: Wednesday, January 08, 2003 6:15 PM Subject: [boost] Re: intrusive tagging allows omision of unneeded headers > Thorsten Ottosen wrote: > [snip] > > class X > > { > > public: > > class tag {}; > > typedef tag X_tag; >^ > > }; > > > > class bar > > { > > public: > > class tag {}; > > typedef tag bar_tag; >^^^ > > }; > > Why these typedefs? Why would one write X::X_tag instead of X::tag for > example? how can we specifiy that we want to specialize for a particular class otherwise? Only by establising a convetion that all (involved) classes have a unique typedef can we destinguish the classes. For example template< typename C > void foo_impl( const C& c, typename C::bar_tag ) { cout << "bar specialised version" << endl; } will only be a candidate when C actually has a typedef bar_tag. due to SFINAE the instantiation is allowed to fail for classes that does not have a bar_tag typdef. And because the above foo_impl is more specialized than template< typename C, typename Tag > void foo_impl( const C& c, Tag t ) { cout << "default version" << endl; } the first foo_impl will be chosen as a better match. regards Thorsten ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
[boost] Re: intrusive tagging allows omision of unneeded headers
Thorsten Ottosen wrote: [snip] class X { public: class tag {}; typedef tag X_tag; ^ }; class bar { public: class tag {}; typedef tag bar_tag; ^^^ }; Why these typedefs? Why would one write X::X_tag instead of X::tag for example? Dirk Gerrits ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost