Re: how to do template constraints with variadic templates ?

2018-07-07 Thread Flaze07 via Digitalmars-d-learn
On Sunday, 8 July 2018 at 02:10:12 UTC, Simen Kjærås wrote: Also, you should probably use CommonType!A for the type of temp, since an int can't hold all the possible values of a long or ulong (or even uint), and you'll thus get unexpected results with large numbers. -- Simen I see, thanks,

Re: how to do template constraints with variadic templates ?

2018-07-07 Thread Simen Kjærås via Digitalmars-d-learn
On Sunday, 8 July 2018 at 00:52:41 UTC, Flaze07 wrote: On Sunday, 8 July 2018 at 00:46:13 UTC, Flaze07 wrote: I want to force the variadic templates's type to be of certain types, I thought doing this would work auto sum( A... )( A a ) if( isIntegral!( typeid( a[ 0 ] ) ) ) { int temp;

Re: how to do template constraints with variadic templates ?

2018-07-07 Thread Flaze07 via Digitalmars-d-learn
On Sunday, 8 July 2018 at 00:46:13 UTC, Flaze07 wrote: I want to force the variadic templates's type to be of certain types, I thought doing this would work auto sum( A... )( A a ) if( isIntegral!( typeid( a[ 0 ] ) ) ) { int temp; foreach( t ; a ) { temp += t; }

how to do template constraints with variadic templates ?

2018-07-07 Thread Flaze07 via Digitalmars-d-learn
I want to force the variadic templates's type to be of certain types, I thought doing this would work auto sum( A... )( A a ) if( isIntegral!( typeid( a[ 0 ] ) ) ) { int temp; foreach( t ; a ) { temp += t; } return temp; } but it gives out error ( note : I want all