[SERVER-37360] Make `StatusWith` accept types with implicit conversion semantics. Created: 27/Sep/18  Updated: 29/Oct/23  Resolved: 27/Sep/18

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.1.4

Type: Improvement Priority: Major - P3
Reporter: ADAM Martin (Inactive) Assignee: ADAM Martin (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Service Arch 2018-10-08
Participants:

 Description   

Use the enable-if for non-explicit constructors trick that `std::optional` uses to make `std::optional< std::unique_ptr< Base > >` accept `std::unique_ptr< Derived >` implicitly.

This will permit things like this, among others:

```
StatusWith< boost::optional< std::unique_ptr< Base > > >
function()

{   if( condition1() ) return boost::none;   if( condition2() ) return std::make_unique< Derived >();   if( condition3() ) return nullptr;   return Status( ErrorCodes::SomethingFailed, "Something is broken" ); }

```



 Comments   
Comment by Githook User [ 27/Sep/18 ]

Author:

{'name': 'ADAM David Alan Martin', 'email': 'adam.martin@10gen.com', 'username': 'adamlsd'}

Message: SERVER-37360 `StatusWith` implicit conversions support.

This uses a variation of the technique used in `std::optional` to
permit chained implicit conversions in constructors.
Branch: master
https://github.com/mongodb/mongo/commit/46fcb2b57e02b54c37112cb247da4d21bc505533

Generated at Thu Feb 08 04:45:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.