Re: overloading address operator and standard containers
On Oct 22, 8:03 pm, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
please consider:
#include <list>
struct aaa {};
struct bbb {
aaa operator & ( void ) const {
return aaa();
}
};
int main ( void ) {
std::list< bbb > a;
}
Is this required to compile or is a compiler within its rights
to reject the code?
Objects in a standard container have to be CopyConstructible.
One of the requirements of CopyConstructible is that the
expression &t return a T* denoting the address of t, see
=A720.1.3.
I recently posted a bug report and have been told that the
code is invalid. The address operator is supposed to be not
overloaded. This, I have learned, should follow from the
provisions in C++03 about allocator::address(). I am still
trying to understand the reasoning, but I feel that I need
some help.
The reasoning is another issue. Why CopyConstructible has this
requirement is beyond me. (If the restriction is necessary, for
some reason, it should be a separate requirement, with an
appropriate name, and not piggy-backed on top of
CopyConstructible. And off hand, I'm not sure why it's
necessary, although on the other hand, it sounds like a
reasonable restriction to me.)
--
James Kanze