Topic: std::basic_string typedefs


Author: "Victor Bazarov" <vAbazarov@dAnai.com>
Date: 28 Aug 2002 18:05:07 GMT
Raw View
"J   rg Baumann" <Joerg.Baumann@stud.informatik.uni-erlangen.de> wrote...
> My C++ problem looks like this:
>
> I have a typedef:
>
>   typedef std::basic_string<C, T, A> mystring;
>
> Now I want to extract the types of C, T and A from mystring:
>
>   typedef typename mystring::traits_type T_extracted;
>   typedef typename mystring::allocator_type A_extracted;
>
> No problem so far, but
>
>   typedef typename mystring::value_type C_extracted;
>
> won't give me C, but T::value_type.
>
> Normally T would be traits<C> and traits<C>::value_type would return C;
> So C_extracted would match C.

Yes, "normally".  That is, if you don't provide your own
traits...

>
> Is this assumption correct, or could there be a case where C_extracted
won't
> match C?

By the definition of std::basic_string, the second argument
does not have to depend on the first.  You could declare
a basic_string like this:

    std::basic_string<char, mytraits<int> >  myspecialstring;

The idea here is that 'char' would be accepted as the type of
most functions (like 'insert' or 'operator +=' or 'at'), but
some would be dealing with 'int' (like the constructor that
takes InputIterators), perhaps for some special functionality...

Victor
--
Please remove capital A's from my address when replying by mail


---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: =?ISO-8859-1?Q?J=F6rg?= Baumann <Joerg.Baumann@stud.informatik.uni-erlangen.de>
Date: Tue, 23 Jul 2002 22:28:25 GMT
Raw View
Hi,

My C++ problem looks like this:

I have a typedef:

  typedef std::basic_string<C, T, A> mystring;

Now I want to extract the types of C, T and A from mystring:

  typedef typename mystring::traits_type T_extracted;
  typedef typename mystring::allocator_type A_extracted;

No problem so far, but

  typedef typename mystring::value_type C_extracted;

won't give me C, but T::value_type.

Normally T would be traits<C> and traits<C>::value_type would return C;
So C_extracted would match C.

Is this assumption correct, or could there be a case where C_extracted won't
match C?



---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]