Add in-place constructor to Maybe
Categories
(Core :: MFBT, enhancement)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox79 | --- | fixed |
People
(Reporter: mozbugz, Assigned: sg)
References
Details
Attachments
(1 file)
The only way to construct a Maybe with a value is through Some(...), which requires the type to be copyable or movable.
This prevents some use cases, like storing a non-copyable non-movable object.
To allow this, we could add an in-place constructor, similar to template <typename... Args> std::optional::optional(std::in_place_t, Args&&...).
| Assignee | ||
Comment 1•5 years ago
|
||
I stumbled upon that a few times as well.
We essentially have the machine for that already through Maybe::emplace, we probably just need to add constructor that calls that.
| Reporter | ||
Comment 2•5 years ago
|
||
emplace assumes (and even MOZ_DIAGNOSTIC_ASSERTs) that we already have Maybe in the default Nothing state (so mIsSome is set to false first), I was hoping the in-place constructor would skip that step and initialize all members to their final values at once.
| Assignee | ||
Comment 3•5 years ago
|
||
Yes, that's right. The original initialization and the MOZ_DIAGNOSTIC_ASSERT might be typically optimized away though? But to be on the "safe" side, the cosntruction could be done right away, yes.
| Assignee | ||
Comment 4•5 years ago
|
||
Updated•5 years ago
|
Updated•5 years ago
|
| Assignee | ||
Updated•5 years ago
|
Comment 6•5 years ago
|
||
Backed out changeset 5200dd8a0de5 (Bug 1645328) for cppunit assertion failures at Maybe.h.
https://hg.mozilla.org/integration/autoland/rev/59d491706a9a143c4e27b9147c2257a4b10755f8
Push with failures:
https://treeherder.mozilla.org/#/jobs?repo=autoland&revision=5200dd8a0de590d710ec23555e65d77d7be6495d&selectedTaskRun=HublIoOUQgyAVv7Ustx7Zg.0
Failure log:
https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=306139440&repo=autoland&lineNumber=1576
| Assignee | ||
Comment 7•5 years ago
|
||
I fixed the patch now and am going to re-land it. Sorry, I introduced this defect by some last-minute changes :(
Comment 9•5 years ago
|
||
| bugherder | ||
Description
•