Boost logo

Boost Users :

From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2003-11-06 14:31:03


Joaquín Mª López Muñoz <joaquin_at_[hidden]> wrote:
> Ben Hutchings ha escrito:
<snip>
> > Without knowing what it is you are trying to do, I cannot offer
> > a workaround.
>
> With pleasure. My original design was
>
> template<typename Type>
> void foo(const Type& x)
> {
> }
>
> (of course the actual code does something useful)
> and I wanted to take advantage of the call_traits<>::param_type
> optimization for basic types.
>
> So, no way? Should I revert to const Type&? Some clever workaround
> to help the compiler swallow the construct? Thx in advance.

I would leave it as const Type &. If you think your compiler is not
smart enough to make a local copy of what x refers to when Type when
that's likely to improve performance, you could use something like
this:

    template<typename Type>
    void foo(const Type & arg_x)
    {
        typename boost::call_traits<Type>::param_type local_x = arg_x;
        ...
    }


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