![]() |
New template rules is bad
New C++ rules are always trying to do "fast" compilation - to compile code, which must be compiled at point of instance only (not during declaration stage). The behaviour is intoducing many wrong limitations. Look at this strange limitation: 1. Can not declare templated friend template< class T> class X { friend class T; //error: using template type parameter 'T' after 'class' //error: friend declaration does not name a class or function }; -- Maksim A Polyanin |
Re: New template rules is bad
Grizlyk wrote:
> New C++ rules are always trying to do "fast" compilation - to compile > code, which must be compiled at point of instance only (not during > declaration stage). The behaviour is intoducing many wrong > limitations. > Look at this strange limitation: > > 1. Can not declare templated friend > > template< class T> > class X > { > friend class T; > //error: using template type parameter 'T' after 'class' > //error: friend declaration does not name a class or function > }; Friendship is overrated. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask |
Re: New template rules is bad
On Jan 30, 5:53 pm, "Grizlyk" <grizl...@yandex.ru> wrote:
> New C++ rules are always trying to do "fast" compilation - to compile code, > which must be compiled at point of instance only (not during declaration > stage). The behaviour is intoducing many wrong limitations. > > Look at this strange limitation: > > 1. Can not declare templated friend > > template< class T> > class X > { > friend class T; > //error: using template type parameter 'T' after 'class' > //error: friend declaration does not name a class or function > > }; Why do you call these "new" template rules? As far as I know, this has been the standard behavior since the standard was adopted almost ten years ago. Best regards, Tom |
Re: New template rules is bad
Victor Bazarov wrote:
> Friendship is overrated. Oh yeah? Try bumming a beer from your enemies! :-) |
Re: New template rules is bad
Grizlyk wrote:
> New C++ rules are always trying to do "fast" compilation - to compile code, > which must be compiled at point of instance only (not during declaration > stage). The behaviour is intoducing many wrong limitations. > > Look at this strange limitation: > > 1. Can not declare templated friend > > template< class T> > class X > { > friend class T; > //error: using template type parameter 'T' after 'class' > //error: friend declaration does not name a class or function > }; > I'd always put this down to gcc compiling a template when it shouldn't. But I can't find the relevant section of the standard that says how a compiler should treat an uninstantiated template. -- Ian Collins. |
Re: New template rules is bad
Grizlyk wrote:
> > New C++ rules are always trying to do "fast" compilation - to compile > code, which must be compiled at point of instance only (not during > declaration stage). The behaviour is intoducing many wrong limitations. > > Look at this strange limitation: > > 1. Can not declare templated friend > > template< class T> > class X > { > friend class T; > //error: using template type parameter 'T' after 'class' > //error: friend declaration does not name a class or function > }; What you encounter here is not some general rule about template instantiation. It is in fact a consequence of [7.1.5.3/2] and the syntax specification that a friend declaration needs an elaborate-type-specifier. In my opinion, these rules could be relaxed without negatively affecting the complexity of compilation. In fact, due to a bug, g++ accepts the following invalid code, which circumvents the provision: template < typename T > class identity { public: typedef T me; }; template < typename T > class my_friend { private: friend class identity< T >::me; char x; }; class The_T { public: static char & peek_friend ( my_friend< The_T > & f ) { return( f.x ); } }; int main (void) { my_friend< The_T > x; The_T::peek_friend( x ); } (See also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21498) Best Kai-Uwe Bux |
Re: New template rules is bad
Thomas Tutone wrote:
> > Why do you call these "new" template rules? As far as I know, this > has been the standard behavior since the standard was adopted almost > ten years ago. Because it can be easy compiled by bcc32 (version 5.5.1) and probably by g++ (version 2.95). -- Maksim A Polyanin |
Re: New template rules is bad
Victor Bazarov wrote:
> > Friendship is overrated. > What does it mean? -- Maksim A Polyanin |
Re: New template rules is bad
Kai-Uwe Bux wrote:
> > What you encounter here is not some general rule about template > instantiation. It is in fact a consequence of [7.1.5.3/2] and the syntax > specification that a friend declaration needs an elaborate-type-specifier. > In my opinion, these rules could be relaxed without negatively affecting > the complexity of compilation. In fact, due to a bug, g++ accepts the > following invalid code, which circumvents the provision: As i can understand, it is even not extention, just error, so can not be used. I think, I will make dummy classes template<class T>class dummy; template<class T> class X { friend class dummy<T>; }; template<class T> class dummy { //pass all X::private into dummy::public }; -- Maksim A Polyanin |
Re: New template rules is bad
On 1/30/07 2:53 PM, in article epoi7n$gt8$1@aioe.org, "Grizlyk" <grizlyk1@yandex.ru> wrote: > > New C++ rules are always trying to do "fast" compilation - to compile code, > which must be compiled at point of instance only (not during declaration > stage). The behaviour is intoducing many wrong limitations. > > Look at this strange limitation: > > 1. Can not declare templated friend > > template< class T> > class X > { > friend class T; > //error: using template type parameter 'T' after 'class' > //error: friend declaration does not name a class or function > } You have it backwards. The new rules for friend declarations (specifically, "extended friend declarations") make the friend T declaration above legal in the next C++ Standard. Most C++ compilers have not yet been updated to recognize this kind of friend declaration (though I believe VC++ 2005 is an exception). So until your C++ compiler adds support for extended friend declarations, your C++ program will be governed by the "old rules", and not by the new ones. Greg |
| All times are GMT. The time now is 11:57 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.