According to C++03 Standard (23.1/3) only copy-constructible class objects can be stored in STL containers. Copy-constructible is described in 20.1.3 and requires that “&” yields address of the object.
Now suppose I have this class:
class Class {
public:
Class* operator&()
{
//do some logging
return this;
}
const Class* operator&() const
{
//do some logging
return this;
}
//whatever else - assume it doesn't violate requierements
};
Can this class objects be legally stored in STL containers?
Yes. In C++03, the CopyConstructible requirements for
&, given valuestof typeTanduof typeconst T, are:&thas typeT*, and gives the address oft, and&uhas typeconst T*, and gives the address ofu.Your overloaded operators have this behaviour; so, assuming the class meets the other CopyConstructible and Assignable requirements, values of this type can be stored in any C++03 container.
C++11 relaxes these requirements, requiring that types be movable or copyable only in containers or operations that specifically have such requirements, and removing the rather odd specification of what
&must do; so your class is still fine, again assuming it meets all the other requirements for the particular container and set of operations you use.