-
pointer's capability
• it extends the scope of pointee to Callable objects
• it's not nullable
$ ^{1} $ cannot be used as non-type template parameter yet
Works in constexpr, just like function type
• sizeof(T*)
function_ref
(as of P0792R5)
• nullable
• reference semantics
• type-erased
• at least 2x the size
std::function
• nullable
• value semantics
• type-erased
• only larger
0 码力 |
49 页 |
575.61 KB
| 1 年前 3
-
transform(convertIntToString);
7: }
## Add a guard to nullable in
- fix one of the asserts X
Add null checks ✗
))
3: i = 9;
4: std::cout << "i=" << i << " prints 9\n"; • views::nullable
— Extra safety for maybe-like types
— std::optional, shared_ptr, raw ptrs, result of find (?)
## How does this work?
01: template nullable="">
02: class nullable_view
0 码力 |
94 页 |
4.56 MB
| 1 年前 3
-
63
Dynamic type ..... 64
Platform types ..... 64
2.1.8 Nullable types ..... 64
Nullability lozenge ..... 65
Definitely non-nullable types ..... 66
2.1.9 Intersection types ..... 67
2.1.10 intersection types ..... 70
2.3.4 Subtyping for integer literal types ..... 70
2.3.5 Subtyping for nullable types ..... 71
2.4 Upper and lower bounds ..... 73
2.4.1 Least upper bound ..... 73
2.4.2 (Kotlin MPP) feature.
The type system of Kotlin distinguishes at compile time between nullable and non-nullable types, achieving null-safety, i.e., guaranteeing the absence of runtime errors caused by
0 码力 |
310 页 |
1.39 MB
| 2 年前 3
-
Adding a non-nullable field to a populated table ..... 44
15.1.1. Adding a NOT NULL field ..... 44
15.1.2. Adding a CHECKed column ..... 46
15.1.3. Using domains to add a non-nullable field ..... columns non-nullable ..... 47
15.2.1. Making an existing column NOT NULL ..... 48
15.2.2. Adding a CHECK constraint to an existing column ..... 48
15.3. Making non-nullable columns nullable again .. '', etc ..... 60
Primary key with NULL entries ..... 61
SUBSTRING results described as non-nullable ..... 61
Gbak -n restoring NOT NULL ..... 61
IN, = ANY and = SOME with indexed subselect ..
0 码力 |
69 页 |
479.63 KB
| 2 年前 3
-
// nullable
var nullable_value: ?[] const u8 = null;
assert(nullable_value == null);
warn("\nnullable 1\ntype: {}
", @運名@typeOf(nullable_value)), nullable_value);
nullable_value nullable_value = "hi";
assert(nullable_value != null);
}
warn("\nnullable 2\ntype: {}
\n",
@運Name(@typeOf(nullable_value)),
nullable_value);
// error union
var number_or_error: error!i32 = error build-exe values.zig
$ ./values
1 + 1 = 2
7.0 / 3.0 = 2.33333325
false
true
false
nullable 1
type: ?[]const u8
value: null
nullable 2
type: ?[]const u8
value: hi
error union 1
type: error!i32
value: error.ArgNotFound
0 码力 |
117 页 |
2.84 MB
| 2 年前 3
-
true);
}
// nullable
const nullable_value = if (os.args.count() >= 2) os.args.at(1) else null;
%%io.stdout.printf("\nnullable\ntype: {}
\nvalue: {}
",
@運名@(typeOf(nullable_value)),
nullable_value); number_or_error);
$ zig build-exe values.zig
$ ./values
1 + 1 = 2
7.0 / 3.0 = 2.333333
false
true
false
nullable
type: ?[]const u8
value: null
error union
type: %[]const u8
value: error.ArgNotFound
## Primitive Primitive Values
|Name|Description|
|---|---|
|true and false|bool values|
|null|used to set a nullable type to null|
|undefined|used to leave a value unspecified|
|this|refers to the thing in immediate
0 码力 |
82 页 |
2.67 MB
| 2 年前 3
-
Data classes ..... 85
Practice ..... 87
Next step ..... 88
Null safety ..... 88
Nullable types ..... 88
Check for null values ..... 89
Use safe calls ..... 89
Use Elvis operator
while loop ..... 337
when expression ..... 338
Ranges ..... 338
Collections ..... 339
Nullable values and null checks ..... 339
Type checks and automatic casts ..... 340
Comments .... 344
Get first item of a possibly empty collection ..... 344
Execute if not null ..... 344
Map nullable value if not null ..... 344
Return on when statement ..... 344
try-catch expression ..... 345
0 码力 |
1299 页 |
32.44 MB
| 2 年前 3
-
default value instead of throwing an exception.
val map = mapOf("key" to 42)
// returns non-nullable Int value 42
val value: Int = map.getValue("key")
val mapWithDefault = map.withDefault as an expression:
fun maxOf(a: Int, b: Int) = if (a > b) a else b
See if-expressions.
Using nullable values and checking for null
A reference must be explicitly marked as null when null value is possible does not hold an integer:
fun parseInt(str: String): Int? {
// ...
}
Use a function returning nullable value:
fun printProduct(arg1: String, arg2: String) {
val x = parseInt(arg1)
val y = parseInt(arg2)
0 码力 |
333 页 |
2.22 MB
| 2 年前 3
-
LE_NAME) VARCHAR(253)
Nullable| MON$PAGE_SIZE | (RDB$PAGE_SIZE) SMALLINT Nullable |
| MON$ODS_MAJOR | (RDB$ODS_NUMBER) SMALLINT Nullable |
| MON$O R) SMALLINT Nullable |
| MON$OLDEST_TRANSACTION | (RDB$TRANSACTION_ID) INTEGER Nullable |
| MON$OLDEST_ACTIVE | (RDB$TRANSACTION_ID) INTEGER Nullable |
Nullable
| MON$NEXT_TRANSACTION | (RDB$TRANSACTION_ID) INTEGER Nullable |
| MON$PAGE_BUFFERS | (RDB$PAGE_BUFFERS) INTEGER Nullable |
< 0 码力 |
63 页 |
261.00 KB
| 2 年前 3
-
default value instead of throwing an exception.
val map = mapOf("key" to 42)
// returns non-nullable Int value 42
val value: Int = map.getValue("key")
val mapWithDefault = map.withDefault used as an expression:
fun maxOf(a: Int, b: Int) = if (a > b) a else b
See if-expressions.
## Nullable values and null checks
A reference must be explicitly marked as null when null value is possible does not hold an integer:
fun parseInt(str: String): Int? {
// ...
}
Use a function returning nullable value:
fun printProduct(arg1: String, arg2: String) {
val x = parseInt(arg1)
val y = parseInt(arg2)
0 码力 |
597 页 |
3.61 MB
| 2 年前 3