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);
}