Re: algorith implementation
Bo Persson posted:
Perhaps something like this:
(It doesn't compile but you get the idea)
enum MyEnum { a,b,c,d,e,f };
template<class T, bool is_signed = ((T)-1 < 0)>
void Func(T arg);
template<class T>
void Func<T,true>(T arg)
{
long i = arg;
}
template<class T>
void Func<T,false>(T arg)
{
long unsigned i = arg;
}
int main()
{
MyEnum obj;
Func(obj);
}
--
Frederick Gotham
Bo Persson posted:
I don't think it is obvious how to select a proper integral type for
n, when you don't know what type Size might be. In this case, if n_arg
happens to be negative, converting it to size_t will not work well.
n, when you don't know what type Size might be. In this case, if n_arg
happens to be negative, converting it to size_t will not work well.
Perhaps something like this:
(It doesn't compile but you get the idea)
enum MyEnum { a,b,c,d,e,f };
template<class T, bool is_signed = ((T)-1 < 0)>
void Func(T arg);
template<class T>
void Func<T,true>(T arg)
{
long i = arg;
}
template<class T>
void Func<T,false>(T arg)
{
long unsigned i = arg;
}
int main()
{
MyEnum obj;
Func(obj);
}
--
Frederick Gotham
Comment