🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2594

Template questions

#2594
From: Bob Kline
Date: Thu, 16 Nov 1995 16:06
46 lines
2417 bytes
A couple of questions about situations in which I'm not sure why
the compiler (Sun's CC in this case) is rejecting some template code.
The first case involves the following code:

template<size_t N> class bitset { ... };
bitset<6> bs;

The compiler complains:
   Error: Template parameter N requires an expression of type unsigned. 

Two questions about this one: is this correct-- does the draft really
not allow an implicit conversion of the template argument here?  And
if it is correct, would it not be prudent to amend the bitset<N> 
class in the draft standard library to take an int instead of a
size_t template argument?  Template syntax is ugly enough already! 
:->}

Here's the other case:

template<size_t N>
bitset<N> operator&(const bitset<N>& lhs, const bitset<N>& rhs)
{
    return bitset<N>(lhs) &= rhs;
}

To which the compiler responds:

"./bitset", line 333: Error: The template argument N is not a type.

Why is this?  The same compiler accepts the "template<size_t N>
class bitset { ... }" quoted above, so I'm puzzled.  However, this 
isn't the only compiler which accepts the first use of a non-type 
template argument and rejects the second, so I'm beginning to suspect
I'm just missing something obvious.  Can someone point it out
to me, please?

--
/*----------------------------------------------------------------------*/
/* Bob Kline                                       Stream International */
/* bob_kline@stream.com               formerly Corporate Software, Inc. */
/* voice: (703) 522-0820 x-311                      fax: (703) 522-5407 */
/*----------------------------------------------------------------------*/

[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <48e62h$itn@lhc.nlm.nih.gov>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: bkline@cortex.nlm.nih.gov (Bob Kline)
Newsgroups: comp.std.c++
Subject: Template questions
Date: 16 Nov 1995 16:06:46 GMT
Organization: National Library of Medicine
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <48e62h$itn@lhc.nlm.nih.gov>
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: 130.14.71.71
X-Newsreader: TIN [version 1.2 PL2]
Content-Length: 1650
X-Lines: 42
Originator: clamage@taumet