Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Allocator named requirements — exceptions

[allocator.requirements.general]/37

Throws: allocate may throw an appropriate exception.

Any limitations on "appropriate" implied elsewhere?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Can a valid custom allocator just throw a double on any request?


Context: implementation of a noexcept function that uses allocator, but has fallback strategy to do something if all allocations fail.

>Solution :

Any limitations on "appropriate" implied elsewhere?

No. "Appropriate" qualifier has no objective meaning. It’s effectively a suggestion to use common sense. There are no limitations on the type thrown from allocate.

Can a valid custom allocator just throw a double on any request?

It would be conforming if the author considers double to be appropriate. I wouldn’t consider it "appropriate" myself, but it’s up to the author to decide.

Context: implementation of a noexcept function that uses allocator, but has fallback strategy to do something if all allocations fail.

You should use a catch-all block:

try {
    ptr = a.allocate();
} catch(...) {
    // deal with it
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading