No way to create a non-nil std.optional in Swift

I'm working with a C++ library that has methods taking std::optionals (sometimes multiple std::optional parameters in a row).

I noticed that there isn't really any built-in way to build a c++ optional in swift. Since there are no initialisers taking a value (there are only those taking nullopt_t or nilLiteral) would have expected some way to assign the value from Swift, either by assigning it to the variable itself, or by assigning to .value but the former fails due to different Types, while the latter fails due to .value being read-only. I thought that assigning to .pointee was the way, but it doesn't actually work (see GitHub - Drejzer/swift-std.optional-minimal: Minimal example for std.optional assignment from swift ).

The only method to pass a non-nil std.optional to a cpp function that I've found is to construct the optional in cpp (by calling make_optional within cpp, since it doesn't seem to work from swift)

Having a bunch of "makeOptional" methods feels clunky, though is probably better that having a bunch on overloads of functions that explicitly take nullopt_t as one of the arguments.

Has there been any consideration for such approach? Or are there some significant problems with this approach? Or am I missing something painfully obvious?

(I was planning to create an issue on GitHub, but was pointed here by the template.)

This is likely a bug in the compiler. var pointee on an instantiation of std::optional should be mutable. Could you please file a GitHub issue for this?

At the moment we don't provide Swift initializers for std::optional that take a wrapped value. This is a piece of missing functionality that we definitely need to support in the future.