File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 1010//
1111//===----------------------------------------------------------------------===//
1212
13- public protocol CxxOptional < Wrapped> {
13+ public protocol CxxOptional < Wrapped> : ExpressibleByNilLiteral {
1414 associatedtype Wrapped
1515
16+ init ( )
17+
1618 func __convertToBool( ) -> Bool
1719
1820 var pointee : Wrapped { get }
1921}
2022
2123extension CxxOptional {
24+ public init ( nilLiteral: ( ) ) {
25+ self . init ( )
26+ }
27+
2228 @inlinable
2329 public var hasValue : Bool {
2430 get {
Original file line number Diff line number Diff line change 22#define TEST_INTEROP_CXX_STDLIB_INPUTS_STD_OPTIONAL_H
33
44#include < optional>
5+ #include < string>
56
67using StdOptionalInt = std::optional<int >;
8+ using StdOptionalString = std::optional<std::string>;
79
810inline StdOptionalInt getNonNilOptional () { return {123 }; }
911
1012inline StdOptionalInt getNilOptional () { return {std::nullopt }; }
1113
14+ inline bool takesOptionalInt (std::optional<int > arg) { return (bool )arg; }
15+ inline bool takesOptionalString (std::optional<std::string> arg) { return (bool )arg; }
16+
1217#endif // TEST_INTEROP_CXX_STDLIB_INPUTS_STD_OPTIONAL_H
Original file line number Diff line number Diff line change @@ -41,4 +41,12 @@ StdOptionalTestSuite.test("std::optional hasValue/value") {
4141 expectNil ( nilOpt. value)
4242}
4343
44+ StdOptionalTestSuite . test ( " std::optional as ExpressibleByNilLiteral " ) {
45+ let res1 = takesOptionalInt ( nil )
46+ expectFalse ( res1)
47+
48+ let res2 = takesOptionalString ( nil )
49+ expectFalse ( res2)
50+ }
51+
4452runAllTests ( )
You can’t perform that action at this time.
0 commit comments