473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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
Jan 30 '07 #1
11 3376
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
Jan 30 '07 #2
On Jan 30, 5:53 pm, "Grizlyk" <grizl...@yandex.ruwrote:
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
Jan 30 '07 #3
Victor Bazarov wrote:
Friendship is overrated.
Oh yeah? Try bumming a beer from your enemies!

:-)
Jan 30 '07 #4
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.
Jan 30 '07 #5
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
Jan 31 '07 #6
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
Jan 31 '07 #7
Victor Bazarov wrote:
>
Friendship is overrated.

What does it mean?

--
Maksim A Polyanin
Jan 31 '07 #8
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
Jan 31 '07 #9

On 1/30/07 2:53 PM, in article ep**********@aioe.org, "Grizlyk"
<gr******@yandex.ruwrote:
>
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

Jan 31 '07 #10
Grizlyk wrote:
Victor Bazarov wrote:
>>
Friendship is overrated.


What does it mean?
It means that in many cases whatever you need 'friend' for
can be accomplished without it.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 31 '07 #11
Victor Bazarov wrote:
>>>
Friendship is overrated.

What does it mean?

It means that in many cases whatever you need 'friend' for
can be accomplished without it.
If keyword "friend" is exist, language must support it completely, because
inheritance must not be only design way.

Composition for example often requires protected interface for non-inherited
classes, that can be easy implemented with friend.

--
Maksim A Polyanin
Jan 31 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris Johnson | last post by:
Greetings all: I come across an interesting question (to me anyway) and I do not know the answer. Code/Questions follow: #include <iostream> #if 0 // uncommenting *should* make call...
21
by: Sebastian Faust | last post by:
Hi, is a construction like the following possible: template<class view_model> class template_clase { protected: template_clase() {} virtual ~template_clase() {}
1
by: Joachim Spoerhase | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I am a XSLT-beginner and i read the XSLT-recommendation of the W3C through. But I did'nt really understand section 5.5 of the latest...
13
by: Walt Karas | last post by:
The following gives an error in the declaration of the member function x() of the class template Tpl, compiliing with a recent version of GCC under Solaris: class A { }; class B { }; ...
16
by: christopher diggins | last post by:
It appears that the following is not considered a class: template<typename T> class C { }; ? So officially is this considered: a class, a template, a class template, or a template class? I...
3
by: Mark P | last post by:
I'm having a problem compiling some template code. Here's a seemingly useless block of code which I've stripped down to illustrate my problem. Why is the second call to a.foo not accepted by the...
3
by: IR | last post by:
Hi, I've been trying to do the following (which doesn't compile) : template<class T, class F = Example<T struct Example { F foo(); };
9
by: neildferguson | last post by:
I am using templates with a little project I am working on. My compiler (GCC) is finding a particular construct ambiguous. Can anyone suggest something I might change in the declaration of class...
2
by: puzzlecracker | last post by:
See it a lot but haven't learn the difference between this two in the context of template. Would someone explain it please? Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.