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 10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
- public protocol CxxOptional < Wrapped> {
13
+ public protocol CxxOptional < Wrapped> : ExpressibleByNilLiteral {
14
14
associatedtype Wrapped
15
15
16
+ init ( )
17
+
16
18
func __convertToBool( ) -> Bool
17
19
18
20
var pointee : Wrapped { get }
19
21
}
20
22
21
23
extension CxxOptional {
24
+ public init ( nilLiteral: ( ) ) {
25
+ self . init ( )
26
+ }
27
+
22
28
@inlinable
23
29
public var hasValue : Bool {
24
30
get {
Original file line number Diff line number Diff line change 2
2
#define TEST_INTEROP_CXX_STDLIB_INPUTS_STD_OPTIONAL_H
3
3
4
4
#include < optional>
5
+ #include < string>
5
6
6
7
using StdOptionalInt = std::optional<int >;
8
+ using StdOptionalString = std::optional<std::string>;
7
9
8
10
inline StdOptionalInt getNonNilOptional () { return {123 }; }
9
11
10
12
inline StdOptionalInt getNilOptional () { return {std::nullopt}; }
11
13
14
+ inline bool takesOptionalInt (std::optional<int > arg) { return (bool )arg; }
15
+ inline bool takesOptionalString (std::optional<std::string> arg) { return (bool )arg; }
16
+
12
17
#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") {
41
41
expectNil ( nilOpt. value)
42
42
}
43
43
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
+
44
52
runAllTests ( )
You can’t perform that action at this time.
0 commit comments