On Thu, Apr 21, 2016 at 4:19 PM, Xidorn Quan <quanxunz...@gmail.com> wrote:
>>
>> 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.

Inlining Init into the factory method doesn't change the fundamentals.
Initialization is still split across two functions. You still can't
use references and |const| as much.

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

I played around with Maybe<> and couldn't come up with something nice.
I may have missed something. Even if there is a nice way involving
Maybe<>, I'm pretty sure you'll still end up having to make a choice
between constructor+Init and constructor+outparam within the factory
method.

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

Reply via email to