On Thu, Apr 21, 2016 at 3:57 PM, Nicholas Nethercote <n.netherc...@gmail.com
> wrote:

> On Thu, Apr 21, 2016 at 3:05 PM, Eric Rescorla <e...@rtfm.com> wrote:
> > So, if we are going to do something along these lines, I would want it
> to be
> > a convention that if you use MakeUnique and the like (as you should) then
> > they automatically validate correct construction and if not return an
> empty
> > pointer.
>
> MakeUnique() just allocates and calls the constructor. If you have
> fallible steps in your intialization then MakeUnique() won't help you;
> you'll still have either call your Init() function afterwards or check
> your nsresult& outparam. So that's not relevant.
>
> Maybe you're referring to factory methods, like this:
>
>   static T* T::New();
>
> which would return null on failure. Such methods can be useful, but
> there's two problems. First, they're not applicable to stack-allocated
> objects. Second, you still have to do your fallible initialization
> *within* the factory method, and so you still have to choose with
> either constructor+Init or constructor+outparam, so you still have to
> make a choice.
>

You can probably merge Init into this factory method, and make constructors
private.

For stack-allocated objects, you can probably return a Maybe<>?

- Xidorn
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to