Closed Bug 1850723 Opened 2 years ago Closed 2 years ago

Add mozilla::Result<V1, E> constructor that receives mozilla::Result<V2, E> where V2 is subclass of V1

Categories

(Core :: MFBT, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
121 Branch
Tracking Status
firefox121 --- fixed

People

(Reporter: arai, Assigned: arai)

References

Details

Attachments

(1 file)

mozilla::Result has the following constructor, which receives different mozilla::Result with convertible error.
Having the same for value type helps using it in bug 1849732 where value type is pointer and it can be subclass.

https://searchfox.org/mozilla-central/rev/e7b8d13b7513b6fbd97d69e882d7faeed05309d0/mfbt/Result.h#524-532

/**
 * Create a (success/error) result from another (success/error) result with a
 * different but convertible error type. */
template <typename E2,
          typename = std::enable_if_t<std::is_convertible_v<E2, E>>>
MOZ_IMPLICIT constexpr Result(Result<V, E2>&& aOther)
    : mImpl(aOther.isOk() ? Impl{aOther.unwrap()}
                          : Impl{aOther.unwrapErr()}) {}

Blocks: 1849732

this can be restricted to bug 1850710's case if necessary.

See Also: → 1850710

Also add std::in_place_t constructor to make the in-place constructor works.

Depends on D191537

Attachment #9359599 - Attachment description: WIP: Bug 1850723 - Add mozilla::Result constructor which takes another result with convertible value. → WIP: Bug 1850723 - Add mozilla::Result constructor which takes another result with convertible value. r?emilio!
Attachment #9359599 - Attachment description: WIP: Bug 1850723 - Add mozilla::Result constructor which takes another result with convertible value. r?emilio! → Bug 1850723 - Add mozilla::Result constructor which takes another result with convertible value. r?emilio!
Attachment #9359599 - Attachment description: Bug 1850723 - Add mozilla::Result constructor which takes another result with convertible value. r?emilio! → Bug 1850723 - Make mozilla::Result constructor take another result with convertible value. r?emilio!
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/7398cacb1ad3 Make mozilla::Result constructor take another result with convertible value. r=emilio,glandium
Flags: needinfo?(arai.unmht)
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/b8d7ddef8a12 Make mozilla::Result constructor take another result with convertible value. r=emilio,glandium
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 121 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: