Boost logo

Boost :

Subject: Re: [boost] [BGL] [PropertyMap] Key param is passed by value in put function
From: Andrew Sutton (andrew.n.sutton_at_[hidden])
Date: 2009-11-18 07:32:00


> I've noticed that the put function that takes a generic put_get_helper map,
>> takes a key param. The question is: why the key param is passed by value? Is
>> any reason for this? The key value is not modified setting the property map.
>>
>>
The original application of keys for property maps only covered some fairly
trivial data types (ints, pointers, and pairs thereof). Passing by value is
perfectly acceptable in these cases.

It's likely that the compiler won't actually generate a copy anyways. The
compiler is allowed to "elide" or omit a copy construction if it feels that
one isn't necessary. There's a good possibility that your key isn't being
copied anyways. Dave Abrahams gives a good account of copy elision here:
http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/.

Andrew Sutton
andrew.n.sutton_at_[hidden]


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