Suppose some data structure:
typedef struct {
std::string s;
int i;
} data;
If I use the field data.s as key when adding i
You cannot use the reference. The map can copy the content. This is I guess implementation dependent.
But tested with the microsoft STL.
struct data
{
data(data const& rhs)
{
a new object will be created here
}
std::string s;
int i;
};
Add some objects to the map and you will run into the copy constructor. This should invalidate your reference.