[prev in list] [next in list] [prev in thread] [next in thread]
List: python-cpp-sig
Subject: [C++-sig] export std::set
From: duranlef () iro ! umontreal ! ca (=?ISO-8859-1?Q?Fran=E7ois_Duranleau?=)
Date: 2006-05-05 17:30:22
Message-ID: Pine.LNX.4.63.0605051324030.18934 () jardin ! iro ! umontreal ! ca
[Download RAW message or body]
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_
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic