From: red floyd on 7 Mar 2010 12:07 On 3/7/2010 2:01 PM, JohnW wrote: > I want to obtain a typedef for the unsigned version of a signed > character type. The example below demonstrates the problem, I have a > typedef for a signed character type but don't know how to obtain the > corresponding unsigned type. > > template< class string_t> > struct Example > { > typedef typename string_t::value_type char_t; > typedef unsigned char_t uchar_t; // doesn't compile > > // ... > }; > template<typename T> struct to_unsigned; template<> struct to_unsigned<char> { typedef unsigned char unsigned_t; }; template<> struct to_unsigned<wchar_t> { typedef unsigned wchar_t unsigned_t; }; template<> struct to_unsigned<short> { typedef unsigned short unsigned_t; }; template<> struct to_unsigned<int> { typedef unsigned int unsigned_t; } template<> struct to_unsigned<long> { typedef unsigned long unsigned_t; }; struct Example { typedef typename string_t::value_type char_t; typedef typename to_unsigned<char_t>::unsigned_t uchar_t; // ... }; -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: Arity in C++0x Variadic Class Method Next: unnamed/anonymous namespace |