On Tue, May 10, 2016 at 9:50 AM, Nick Fitzgerald
<[email protected]> wrote:
> Or, if we don't want to boil too many oceans and have something closer to
> our usage of bool and not worry about wrapping types:
>
> class Result
> {
> public:
> enum class Type : uint32_t
> {
> Ok,
> Oom,
> Exception,
> // Etc...
> };
>
> private:
> Type type_;
>
> public:
> // Helper methods here...
>
> explicit operator bool () { return type_ == Type::Ok;}
>
> // Etc...
> };
I was imagining something like this, though I wouldn't bother with
distinguishing between different kinds of failures, because that's not
something we've ever done so I don't see why we'd start now.
> If we are going to leave bool behind, I think we should use something
> Rustic:
>
> template <typename T, typename E>
> class MOZ_MUST_USE_TYPE Result : public mozilla::Variant<T, E>
> {
> public:
> // Helper methods here...
>
> explicit operator bool () { return is<T>(); }
>
> // Etc...
> };
That's total overkill for the bool case -- we don't need to
parameterize on either T or E. But if we wanted to be more principled
with fallible functions that return pointers, then a Result<T> could
be useful.
Anyway, I'll stick with the MOZ_MUST_USE-on-bool changes for now.
Nick
_______________________________________________
dev-tech-js-engine-internals mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals