Boost logo

Boost :

From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2008-03-26 06:32:32


On Wed, Mar 26, 2008 at 7:11 AM, <dherring_at_[hidden]> wrote:
> Quick question:
>
> In boost/pool/detail/gcd_lcm.hpp, why does
>
> template <typename Integer>
> Integer lcm(const Integer & A, const Integer & B);
>
> take its parameters as const references instead of just passing the
> values?
>

This avoids unnecessary copying in case existing 'Integer'
objects/instances are passed to the function. For example, you can use
this to make your own 'Integer-conforming' class and avoid extraneous
copies. In case you pass in values, you cause the creation of
temporaries -- which the compiler can optimize out later for you.

-- 
Dean Michael C. Berris
Software Engineer, Friendster, Inc.
[http://blog.cplusplus-soup.com]
[mikhailberis_at_[hidden]]
[+63 928 7291459]
[+1 408 4049523]

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk