Inserting a temporary std::string into a set: is it a dangling reference or a copy?

Hi,

The simplest question. I have the following scenario:

1
2
3
4
5
6
7
8
9
10
11
class container {
   std::set<std::string> names_;
public:
void make_current(const std::string& s) {
   names_.insert(s);
}
//....
};

container cont;
cont.make_current( "56" );


My question is this: a temporary std::string object is created at the "entrance" of make_current method, from a const char* (value 56). This temporary is then inserted into a std::set called names_. Does this copy the temporary into the set or does it insert a reference to this temporary?

Thanks,

Juan

P.S.: it seems to me that the set being of type std::string, should make a copy of the temporary, so there is no problem. Am I right?
Last edited on
Where do you say that the set's value_type is anything?

Look at:
http://www.cplusplus.com/reference/set/set/insert/

"copy or move"
Sorry forgot the std::string on set definition.
Now, does my question makes sense?

Regards,
Juan
It's a copy. You can't store references in standard containers.
Topic archived. No new replies allowed.