Boost logo

Boost Users :

From: Sakharuk, Vlad \(GMI Development\) (Vlad_Sakharuk_at_[hidden])
Date: 2008-03-25 13:16:06


Compiler does optimize it away. But it should compile it first to
validate correctness of the code.
Btw on "g++ (GCC) 3.4.6 20060404 (Red Hat 3.4.6-3)" I do not see those
warnings.

I also prefer to use:
if(n==2)
if(n==3)//without else.

-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Hicham Mouline
Sent: Tuesday, March 18, 2008 2:56 PM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] template int argument

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_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Steven
Watanabe
Sent: 18 March 2008 18:47
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] template int argument

AMDG

Hicham Mouline wrote:
> hi,
>
> I have a template function <typename cT, typename tT, int n> {
> ....
> 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<typename cT, typename tT, int n>
void f() {
    double array[n];

    do_n_specific_code(array);

}

In Christ,
Steven Watanabe

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
--------------------------------------------------------

This message w/attachments (message) may be privileged, confidential or proprietary, and if you are not an intended recipient, please notify the sender, do not use or share it and delete it. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Merrill Lynch. Subject to applicable law, Merrill Lynch may monitor, review and retain e-communications (EC) traveling through its networks/systems. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or error-free. This message is subject to terms available at the following link: http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you consent to the foregoing.
--------------------------------------------------------


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net