From -1283940864881919957
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,cbdacaca1754b606,start
X-Google-Attributes: gidf78e5,public
From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
Subject: Friends and templates
Date: 1999/06/02
Message-ID: <37542AC3.2312DCBD@cs.tu-berlin.de>#1/1
X-Deja-AN: 484787217
Content-Transfer-Encoding: 7bit
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
X-Original-Date: Tue, 01 Jun 1999 20:47:31 +0200
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: news@news.unimelb.edu.au
X-Trace: izvestia.its.unimelb.edu.au 928311927 10993 128.250.29.16 (2 Jun 1999 08:25:27 GMT)
Organization: Technische Universitaet Berlin, Deutschland
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUAN1TqW+EDnX0m9pzZAQEuAQF/T9M/OXlREH+nKrW8d1kiq4qfktVxyj/7 BaAa2+Yd/V1LkbDHXeMz2yzXEccll2FN =GA4W
Mime-Version: 1.0
NNTP-Posting-Date: 2 Jun 1999 08:25:27 GMT
Newsgroups: comp.std.c++

Hi,

in "The C++ Programming Language", 3rd edition, I've found the following
example (C.13.2, pp. 854-855; I've simplified it a bit):

template<class C> class Basic_ops {
	friend bool operator==(const C&, const C&);
};

template<class C> bool operator==(const C& a, const C& b) {...}

The text says that "a friend declared within a template is itself a
template". This seems to contradict the example in IS 14.5.3
[temp.friends]:

template<class T> task<T>* preempt(task<T>*);

template<class T> class task {
	...
	friend void process(task<T>*);
	friend task<T>* preempt<T>(task<T>*);
	...
};

Here, the text says that process is not a function template
specialization. Am I missing something or is C++PL really incorrect
here?

Then, the text in IS says "...because process does not have explicit
template-arguments...". Does this mean that process can have explicit
template-arguments even without prior declaration, i.e. would the code
be legal if I changed the declaration to

friend void process<T>(task<T>*);

The text "if the name of the friend is a ... template-id, the friend
declaration refers to a specialization of a function template" doesn't
seem to require that the function template is declared before the friend
declaration. Is this requirement implicit or is it not necessary to
declare process as a template in this case?

Next, is it correct that declaration 1 below refers to the preempt
template while declaration 2 declares a new non-template function?

friend task<T>* ::preempt(task<T>*);	// 1
friend task<T>* preempt(task<T>*);	// 2

Finally, the text under the example says that preempt refers to a
template "because ... preempt has an explicit template-argument <T>".
Would the code be still legal if I replaced <T> with <>? 

Bye

Roman
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



