
hi,
I have a template function

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hicham Mouline wrote:
| hi,
|
| I have a template function

AMDG Hicham Mouline wrote:
hi,
I have a template function
{ .... double array[n]; if (n==2) binomial code else if (n==3) trinomial code (array[0] array[1] array[2]) else ....
compiler tries to compile the "trinomial code" code even when the template is instantiated with n=2, and that gives warnings because of array[2]
Is there a way to make the compiler ignore the non-binomial code ? rds,
You'll have to split it out into a separate function and use template
specialization/overload resolution.
template<int n>
void do_n_specific_code(double (&array)[n]);
template

That's what I thought... What forbids the compiler from optimizing away the test on n value, during the template instantiation process? Thanks, -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: 18 March 2008 18:47 To: boost-users@lists.boost.org Subject: Re: [Boost-users] template int argument AMDG Hicham Mouline wrote:
hi,
I have a template function
{ .... double array[n]; if (n==2) binomial code else if (n==3) trinomial code (array[0] array[1] array[2]) else ....
compiler tries to compile the "trinomial code" code even when the template
is instantiated with n=2, and that gives warnings because of array[2]
Is there a way to make the compiler ignore the non-binomial code ? rds,
You'll have to split it out into a separate function and use template
specialization/overload resolution.
template<int n>
void do_n_specific_code(double (&array)[n]);
template

I realize one thing more. My code refers to cT and tT template arguments:
Template
hi,
I have a template function
{ .... double array[n]; if (n==2) binomial code else if (n==3) trinomial code (array[0] array[1] array[2]) else ....
compiler tries to compile the "trinomial code" code even when the template
is instantiated with n=2, and that gives warnings because of array[2]
Is there a way to make the compiler ignore the non-binomial code ? rds,
You'll have to split it out into a separate function and use template
specialization/overload resolution.
template<int n>
void do_n_specific_code(double (&array)[n]);
template
participants (3)
-
Francesco Biscani
-
Hicham Mouline
-
Steven Watanabe