Topic: [Q] default arguments to templates


Author: jason@cygnus.com (Jason Merrill)
Date: Thu, 28 Jul 1994 21:16:00 GMT
Raw View
>>>>> Howard P Henson <hhenson@inyanga.cs.wits.ac.za> writes:

> : >template<class T, int i=2>

>  This works fine under the Borland compiler. This does not work
> under the g++ 2.5.8 (I tried!) Unfourtuantly I do not know about 2.6.0
> though it did seem from the announced specs it could do it.

Nope, it can't.  It should work in 2.6.1, though.

Jason




Author: jsm@mitekgold1 (Shane McRoberts)
Date: 27 Jul 1994 17:48:19 GMT
Raw View
: In article <MAV.94Jul18101829@gaia.cc.gatech.edu> mav@cc.gatech.edu writes:
: >
: >I was under impression thet the following code should be legal, but
: >neither g++ 2.6.0 nor CenterLine (Cfront 3.0) seem to accept it:
: >
: >template<class T, int i=2>
: >class A
: >{
: >  T value[i];
: >};
: >
: >A<float>      a1;

This is, in fact, correct C++ according to the ARM (14.1).  It is
possible that the working paper puts more restrictions on the
_argument-declaration_ in a _template-declaration_, but it seems
unlikely.

This is probably a bug (unimplemented feature) in g++ and should
be reported to gnu.g++.bug.

Ron G.'s advice not withstanding, no compiler currently implements
every feature of ARM or the working paper.  Workarounds are a fact
of C++ life (for now).

The workaround is evidently to not initialize the int template-argument.
This requires specifying it in the template-class-name (e.g., A<float,2>)
which is unfortunate, but by reporting it to gnu.g++.bugs, you increase
the likelihood that it will be fixed soon.

Shane

===============================================================================
 j.shane.mcroberts |
mitek systems, inc.| We are currently experiencing technical difficulties that
                   | prevent replies to this posting.  Please send mail to
 jsm@miteksys.com  | <== this address.
===============================================================================




Author: hhenson@inyanga.cs.wits.ac.za (Howard P. Henson)
Date: 28 Jul 1994 15:39:09 GMT
Raw View
Ronald F. Guilmette (rfg@netcom.com) wrote:
: In article <MAV.94Jul18101829@gaia.cc.gatech.edu> mav@cc.gatech.edu writes:
: >
: >I was under impression thet the following code should be legal, but
: >neither g++ 2.6.0 nor CenterLine (Cfront 3.0) seem to accept it:
: >
: >template<class T, int i=2>
: >class A
: >{
: >  T value[i];
: >};
: >
: >A<float>      a1;

: Looks OK to me (and to at least one compiler I have here).

: Maybe you need a newer/different compiler.
 This works fine under the Borland compiler. This does not work
under the g++ 2.5.8 (I tried!) Unfourtuantly I do not know about 2.6.0
though it did seem from the announced specs it could do it.
 Depending on what you need it for you can overcome this small
problem by other methods.

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~                   Rotating the object by                                 ~
~          Howard Henson <hhenson@inyanga.cs.wits.ac.za>                   ~
~           mans quest for object orientaion ends here!                    ~
~                                                                          ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Wed, 27 Jul 1994 06:57:57 GMT
Raw View
In article <MAV.94Jul18101829@gaia.cc.gatech.edu> mav@cc.gatech.edu writes:
>
>I was under impression thet the following code should be legal, but
>neither g++ 2.6.0 nor CenterLine (Cfront 3.0) seem to accept it:
>
>template<class T, int i=2>
>class A
>{
>  T value[i];
>};
>
>A<float>      a1;

Looks OK to me (and to at least one compiler I have here).

Maybe you need a newer/different compiler.

--

-- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting -------------------
---- domain addr: rfg@netcom.com ----------- Purveyors of Compiler Test ----
---- uucp addr: ...!uunet!netcom!rfg ------- Suites and Bullet-Proof Shoes -




Author: mav@gaia.cc.gatech.edu (Maurizio Vitale)
Date: 18 Jul 1994 14:18:29 GMT
Raw View
I was under impression thet the following code should be legal, but
neither g++ 2.6.0 nor CenterLine (Cfront 3.0) seem to accept it:

template<class T, int i=2>
class A
{
  T value[i];
};

A<float>      a1;

On the same line (but I think this is not allowed) I'd like to have
something like:

template<class Node, class Edge=Default_Edge> class graph {...};

Someone knows what kind of worm cans something like this would open?
Thanks,

--
    Maurizio Vitale
 _______________
|        _      |\   e-mail: mav@cc.gatech.edu     | How many times can
|  /|/| '_) | ) | |  voice:  (404) 881-6083 (home) | a man turn his head,
| | | |_(_|_|/  | |          (404) 853-9382 (work) | and pretend that he
|_______________| |                                | just doesn't see ?
 \_______________\|  fax:    (404) 853-9378        |  - Bob Dylan