Afficher un message
Vieux 07/04/2008, 19h29   #2
Fei Liu
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Upsigning or downsigning

Damian wrote:
> Is there any way to manipulate a template parameter to change its
> signedness?
>
> For example,
>
> template <typename T>
> void foo(signed T a, unsigned T b) {
>
> }
>
> defines a templated function that is instantiated with a base numeric
> type (e.g. int or long) but is referred by signed and unsigned
> variants.
>
> Also, how do I convert a typename to signed or unsigned? For example,
> if I had some variable k I wanted to cast to the unsigned variant of
> type T, I'd like to be able to do
>
> j = (unsigned_type(T))k
>
> but I'm not sure if it's possible to do something like that. Is there
> anyway to "upsign" (i.e. convert a numeric type to signed) or
> "downsign" (i.e. convert a numeric type to unsigned) similar to how
> one might upcast or downcast a number?
>
> Thanks!
>
> Damian Eads


Yes, because signed-ness is part of a function signature that function
overloading uses. You can devise a 'type-of' class template to determine
if a type is signed or unsigned at compile time.

Fei
  Réponse avec citation
 
Page generated in 0,05274 seconds with 9 queries