Topic: Simple grammar question


Author: rozga@lily.aerc.colostate.edu (Anthony A. Rozga)
Date: Fri, 29 Apr 1994 16:00:20 GMT
Raw View
In article <CozMvH.457@inmet.camb.inmet.com> kerch@albion.camb.inmet.com (Kerchival F. Holt) writes:
>
>Here is the code you gave:
>    template<class T>
> class Foo { /* details omitted */ };
>
>    class Bar {
>
>        template<class T> friend class Foo;
>
>    };
>
>At first glance the problem seems to be that the scope of the <class T>
>does not extend into the class Bar declaration. But perhaps you intend for
>these to be different template parameter lists.
>

  Exactly.  I want all instantiations of Foo to be friend to Bar. (i guess
  using T in both places was confusing)

>There is a confusing passage at the bottom of page 364 in Lippman's
>book. Here is the text:
>
>    template <class Type>
>    class Queue {
>       template <class T> // NOTE: T, not Type
>    friend ostream&
>    operator<<(ostream&,Queue<T>&);
>    ...
>    };
>
>It seems the unbound <T> means "allow all instances of ostream operator<<".
>Can this be? Lippman later seems to correct this by not using the <class T>.
>I see nothing in the standard to support this definition.
>

Look at section 7.8.  There he shows an example of an unbound template friend
class declaration, which is what I am trying to achieve in my example.  It
seems to me that the statement in the ARM (sec. 11.4, pg 249):

 "Note that only an elaborated-type-specifier and not a
  complete class declaration is allowed in a friend
  declaration..."

taken with the Grammar Summary chapter make it impossible to derive such a
declaration.  What am I missing?

Tony Rozga







Author: jason@cygnus.com (Jason Merrill)
Date: Sat, 30 Apr 1994 00:35:27 GMT
Raw View
>>>>> Anthony A Rozga <rozga@lily.aerc.colostate.edu> writes:

>   Simple question here....Is this legal C++?

>    template<class T>
>    class Foo { /* details omitted */ };

>   class Bar {

>        template<class T> friend class Foo;

>    };

No.  Member templates are not allowed in the language as specified by the
ARM, and I believe that the resolution passed in San Diego to add member
templates only added them for non-static member functions.

Jason




Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Tue, 3 May 1994 04:14:44 GMT
Raw View
rozga@lily.aerc.colostate.edu (Anthony A. Rozga) writes:

>  Simple question here....Is this legal C++?
>
>  class Bar {
>       template<class T> friend class Foo;
>   };
>
>  My interpretation of the ARM says "hmmh, I don't know", Lippman's C++
>  Primer says "yes", an engineer at SUN says "no" but their compiler (3.0.1)
>  says "yes".  Thanks.

According to the ARM, this is definitely not legal C++.  (ARM 14.1:
"A *template-declaration* may appear only as a global declaration.")

Some compilers, notably Cfront, allow it.  Some compilers don't.

I think that someone recently posted here saying that the ANSI/ISO C++
committee had recently *rejected* a proposal to allow it.  If this
is true, then it's not legal C++; otherwise I guess you'd have to
say that the jury is still out - but don't use it in programs that
you want to be widely portable.

--
Fergus Henderson - fjh@munta.cs.mu.oz.au




Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Fri, 6 May 1994 04:09:17 GMT
Raw View
In article <9412314.13018@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus Henderson) writes:
>rozga@lily.aerc.colostate.edu (Anthony A. Rozga) writes:
>
>>  Simple question here....Is this legal C++?
>>
>>  class Bar {
>>       template<class T> friend class Foo;
>>   };
>>
>>  My interpretation of the ARM says "hmmh, I don't know", Lippman's C++
>>  Primer says "yes", an engineer at SUN says "no" but their compiler (3.0.1)
>>  says "yes".  Thanks.
>
>According to the ARM, this is definitely not legal C++.  (ARM 14.1:
>"A *template-declaration* may appear only as a global declaration.")
>
>Some compilers, notably Cfront, allow it.  Some compilers don't.
>
>I think that someone recently posted here saying that the ANSI/ISO C++
>committee had recently *rejected* a proposal to allow it.  If this
>is true, then it's not legal C++; otherwise I guess you'd have to
>say that the jury is still out - but don't use it in programs that
>you want to be widely portable.

 Now we have member templates (not to be confused with
template members) friend templates are likely to be accepted,
if they havent been already (IMHO).

 Far too much code simply cant be written otherwise.


--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,      CSERVE:10236.1703
        6 MacKay St ASHFIELD,     Mem: SA IT/9/22,SC22/WG21
        NSW 2131, AUSTRALIA




Author: rozga@lily.aerc.colostate.edu (Anthony A. Rozga)
Date: Wed, 27 Apr 1994 21:40:21 GMT
Raw View
Hi,

  Simple question here....Is this legal C++?

   template<class T>
   class Foo { /* details omitted */ };

  class Bar {

       template<class T> friend class Foo;

   };

  My interpretation of the ARM says "hmmh, I don't know", Lippman's C++
  Primer says "yes", an engineer at SUN says "no" but their compiler (3.0.1)
  says "yes".  Thanks.

  Tony Rozga




Author: kerch@albion.camb.inmet.com (Kerchival F. Holt)
Date: Thu, 28 Apr 1994 21:11:40 GMT
Raw View
You must be referring to section 7 in Lippman's book (Primer, 2nd
edition) where he uses constructs of the following form:

    template <class T>
    class QueueItem {
 friend class Queue<T>;
 ...
    }

I have no problem with this.

Here is the code you gave:
    template<class T>
 class Foo { /* details omitted */ };

    class Bar {

        template<class T> friend class Foo;

    };

At first glance the problem seems to be that the scope of the <class T>
does not extend into the class Bar declaration. But perhaps you intend for
these to be different template parameter lists.

There is a confusing passage at the bottom of page 364 in Lippman's
book. Here is the text:

    template <class Type>
    class Queue {
       template <class T> // NOTE: T, not Type
    friend ostream&
    operator<<(ostream&,Queue<T>&);
    ...
    };

It seems the unbound <T> means "allow all instances of ostream operator<<".
Can this be? Lippman later seems to correct this by not using the <class T>.
I see nothing in the standard to support this definition.

Kerch Holt
Intermetrics Microsystems Software Inc.
kerch@camb.inmet.com
--
Kerch Holt
Intermetrics Microsystems Software Inc.
kerch@camb.inmet.com