[C++-sig] export std::set

François Duranleau duranlef at iro.umontreal.ca
Fri May 5 19:30:22 CEST 2006


On Thu, 4 May 2006, Andreas Beyer wrote:

>> Why not put the key parameter as a const reference instead of copying?
>>
> Good point, no problem with contains() and remove(). Is there no risk
> with add()? What if the object that is passed to add() does not exist
> beyond its current scope? Like this:
>
> void some_function(py_set<string>& a_set)
> {
>    string s = "hello world";
>    a_set.add(s);
> }
> py_set<string> my_set;
> some_function(my_set);
> // Is it certain that 's' in 'my_set' still exists at this point?

Well, what is the difference between the local variable s in this example 
and the 'local' variable key in add? The only way it would be a risk is if 
no copy of the object was put in the set, but only a reference or pointer, 
and in that case, passing the argument by copy is garantied to cause 
trouble.

-- 
François Duranleau
LIGUM, Université de Montréal

"Just as a drop of water causes ripples in a pond,
  where there is anger and fear, there is conflict."
                                    - Folken, in _The Vision of Escaflowne_


More information about the Cplusplus-sig mailing list