How detect and handle if object is used as l-value or as r-value?
<p>I have a container class called <code>Properties</code>. I want to add to it <code>operator[](const std::string &amp; name)</code> which will return property with specified name.</p>

<p>Now lets consider that there is no property with specified name. In this case I wan't to add new <code>Property</code> with specified name to my <code>Properties</code> if it is used as l-value and throw exception otherwise.</p>

<pre><code>Properties pts;
pts.add("name1", val1);
pts.add("name2", val2);
pts["name1"] = val3; //OK
pts["name3"] = val1; //OK creating new Property with value = val1
cout &lt;&lt; pts["name4"]; //Ooops can't find Property with name = "name4", so throwing an exception
</code></pre>

<p>Is this possible in C++? How can I write such <code>operator[]</code>?</p>
