S
stephen.diverdi
Any suggestions on how to accomplish something like this doScale
function?
#include <stdio.h>
template < typename T, T scale >
T doScale ( const T &x )
{
return ( x * scale );
}
int main ()
{
float x = 1;
float y = doScale< float, 2.0f >( x );
printf( "%f %f\n", x, y );
int a = 1;
int b = doScale< int, 3 >( a );
printf( "%d %d\n", a, b );
return 0;
}
I want to have the second template parameter be a constant of a type
that is determined by the first template parameter. g++ and comeau
both reject it. If you're curious, I'm looking to replace a run-time
constant with a compile-time constant in some critical code. Thanks,
-stephen diverdi
(e-mail address removed)
function?
#include <stdio.h>
template < typename T, T scale >
T doScale ( const T &x )
{
return ( x * scale );
}
int main ()
{
float x = 1;
float y = doScale< float, 2.0f >( x );
printf( "%f %f\n", x, y );
int a = 1;
int b = doScale< int, 3 >( a );
printf( "%d %d\n", a, b );
return 0;
}
I want to have the second template parameter be a constant of a type
that is determined by the first template parameter. g++ and comeau
both reject it. If you're curious, I'm looking to replace a run-time
constant with a compile-time constant in some critical code. Thanks,
-stephen diverdi
(e-mail address removed)