Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #7892

Re: Traits in STL

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: Traits in STL
Date Sun, 17 Jul 2011 11:46:55 +1200
Lines 42
Message-ID <98em9fFi81U2@mid.individual.net> (permalink)
References <04673f16-5afd-47f2-9266-e3f4a00fec6a@fv14g2000vbb.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net FTJzLyIMtIM+bul3rhlctgeOG5Yf1UCLVZoRj6N61jY5fy+OSe
Cancel-Lock sha1:YDkCnEF4fdBP1gaJDha77pxtob8=
User-Agent Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4
In-Reply-To <04673f16-5afd-47f2-9266-e3f4a00fec6a@fv14g2000vbb.googlegroups.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.c++:7892

Show key headers only | View raw


On 07/17/11 11:36 AM, Narinder wrote:
> Hello
>
> I am somewhat curious about the reason for the way types in the STL
> are dependant on trait classes. For example the template class
> basic_string is defined as :
>
> template<class charT,
>           class traits = char_traits<charT>,
> 		 class Allocator = allocator<charT>  >
> 		>
> class basic_string;
>
> but not as:
>
> template<class charT,
>           template<class>  class traits_t = char_traits,
> 		 template<class>  class Allocator_t = allocator>
> 		>
> class basic_string
> {
> 	typedef traits_t<charT>  traits;
> 	typedef Allocator_t<charT>  Allocator;
> ....
>
>
> You would think (or perhaps not) that the second approach is less
> error prone since it would be less likely that your traits would be
> inconsistent with the char type. The only reason I can think of is
> that you may have a traits class specifically for char which wouldn't
> make sense for any other types and thus wouldn't need to be a
> template. In that case you could always write it as template class and
> use traits to activate it only for char types.

Another reason could be a lot of compilers didn't support template 
template parameters when the standard was published (as an aside, I 
don't think template template parameters are used anywhere in the 
current standard library).  Not being able to support std:;string would 
have been a bit of a problem!

-- 
Ian Collins

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Traits in STL Narinder <narinder.claire@gmail.com> - 2011-07-16 16:36 -0700
  Re: Traits in STL Ian Collins <ian-news@hotmail.com> - 2011-07-17 11:46 +1200
    Re: Traits in STL Narinder <narinder.claire@gmail.com> - 2011-07-16 16:54 -0700
      Re: Traits in STL Ian Collins <ian-news@hotmail.com> - 2011-07-17 12:08 +1200
        Re: Traits in STL Narinder <narinder.claire@gmail.com> - 2011-07-16 17:13 -0700
          Re: Traits in STL Ian Collins <ian-news@hotmail.com> - 2011-07-17 14:09 +1200
  Re: Traits in STL Qi <no@no.com> - 2011-07-17 09:47 +0800

csiph-web