Hacker News new | ask | show | jobs
by klyrs 1748 days ago
> C++ constructors cannot express fallibility.

No, they can. They can throw exceptions. My suggestion moves unsafe-construction onto the heap. Not ideal for a whole host of reasons, including a need to null-check the result -- but you can then move the object to the stack, and drop the unique_ptr. But if you're tying one hand behind your back, contortions will be necessary to accomplish the mundane.

1 comments

You can have a named factory function returning an optional<T> (or your preferred fallible type).
Right, right... I still haven't adopted the '17 features yet.