Hello, I'm trying to call C++ function that returns std::vector< std::optional< std::string > > and return it in Swift as [String?]
As std::optional cannot be directly handled by Swift, I've tried to make proxy function
If I try to make it with following signature:
swift::Array< swift::Optional< swift::String > > ConvertOptList( std::vector< std::optional< std::string > > param);
I'm getting following error:
Constraints not satisfied for class template 'Array' [with T_0_0 = swift::Optionalswift::String]
Because 'swift::isUsableInGenericContext<swift::Optionalswift::String >' evaluated to false
If I try to return std::vector of Swift optional
std::vector< swift::Optional< swift::String > > ConvertOptList( std::vector< std::optional< std::string > > param)
{
std::vector< swift::Optional< swift::String > > res;
for( auto& obj: param )
{
if( obj )
{
auto opt = swift::Optional< swift::String >::some( swift::String( *obj ) );
res.push_back( opt );
}
else
{
auto opt = swift::Optional< swift::String >::none();
res.push_back( opt );
}
}
return res;
}
I'm getting following errors:
Undefined symbols:
Linker command failed with exit code 1 (use -v to see invocation)
Without details on undefined symbols, but problem is with push_back.
Is there a way to correctly convert such data?
P.S. also, if I try to make function that return one optional string
swift::Optional< swift::String > GetOptString( bool fill );
it isn't imported in Swift. Is it bug or also some limitation?