This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: operator new/delete forwarding
- From: Martin Sebor <sebor at roguewave dot com>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 20 Jul 2006 13:57:14 -0600
- Subject: Re: operator new/delete forwarding
- References: <28E2CC50-386A-47DC-8A47-29357E013744@apple.com>
Howard Hinnant wrote:
[...]
I view this forwarding as a valuable convenience to the client, however
I believe it is incomplete, and slightly wrong. I respectfully propose
the following slight alteration:
This makes sense but I wonder why the standard doesn't specify
the nothrow operators just the way you describe instead of going
through the same steps as for the ordinary forms and using the
"as if" phrase? It almost looks like the intent was for both
operators to be implemented in terms of the same (unspecified)
function but not by calling each other, i.e., like so (calling
new_handler omitted):
void* op_new (size_t n, bool nothrow) {
void *p = malloc (n);
if (0 == p && !nothrow)
throw bad_alloc ();
return p;
}
void* operator new (size_t n) {
return op_new (n, false);
}
void* operator new (size_t n, const nothrow_t&) {
return op_new (n, true);
}
Martin