From 6795529356137134868
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,b3e3d077abe0c9b3
X-Google-Attributes: gidf78e5,public
From: phalpern@truffle.ma.ultranet.com (Pablo Halpern)
Subject: Re: Count signature
Date: 1998/05/19
Message-ID: <35619a8d.8526337@news.ma.ultranet.com>#1/1
X-Deja-AN: 354695872
Content-Transfer-Encoding: 7bit
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <6j0bmk$m0v@bgtnsc03.worldnet.att.net> <6j6bro$kok$1@nnrp1.dejanews.com>
X-Ultra-Time: 19 May 1998 14:57:17 GMT
Mime-Version: 1.0
Originator: clamage@taumet
X-NNTP-Posting-Host: truffle.ultranet.com
X-UID: 0000000001
X-Status: $$$T
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@ultra.net
Organization: UltraNet Communications, Inc.   http://www.ultranet.com/
Newsgroups: comp.std.c++


dietmar.kuehl@claas-solutions.de wrote:

>
>  template <typename It, typename T>
>  typename iterator_traits<It>::size_type
>  count(It begin, It end, T const &val);
>
>The reason for the original version was simply that at this time there was
>apparently no way to determine the size_type associated with the iterator.
>Thus, the user was required to pass an object of appropriate type. With
>'iterator_traits' the interface could be made safer (ie. the user cannot mess
>up the type of the count anymore) and more convenient.

The adapted SGI (and I think ObjectSpace) libraries have both versions,
depending on the capabilities of your compiler. I think this is
wrong-headed.  For compilers that can't support traits classes, I think
the better definition is:

  template <typename It, typename T>
  unsigned long count(It begin, It end, T const &val);

This allows users of slightly outdated compilers to use the newer
calling convention without worrying about changing it when they upgrade
compilers. The only time unsigned long is inappropriate is if you define
your own size type which is larger than unsigned long. If you are doing
that kind of thing, then I doubt the older compilers will be up to the
task anyway. So lets just keep it simple for the 99% case.  Anybody from
the SGI adaptation effort listening?

When I teach STL on older compilers, I provide a header file that
defines count() as above and defines distance() similarly. It makes it
easy to compile my lab solutions with both old and new compilers.

BTW, I also get around the std:: namespace problem by using adding the
-Dstd= option to compiler commands for most compilers.  This causes
std::cout to be preprocessed into just ::cout, which works great for
compilers without namespaces.

-------------------------------------------------------------
Pablo Halpern                   phalpern@truffle.ultranet.com

I am self-employed. Therefore, my opinions *do* represent 
those of my employer.


[ 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              ]




