1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.parser: add a generated .all(.flag1|.flag2) method to [flag] enums

Unlike `.has(.flag1|.flag2)`, which is true, for any of `.flag1` or `.flag2`,
the new method `.all()` tests whether *all flags* are set at the same time.
This commit is contained in:
Delyan Angelov
2021-09-26 21:24:35 +03:00
parent 09dfc3f301
commit 6a2ef733de
3 changed files with 42 additions and 3 deletions

View File

@@ -5344,14 +5344,23 @@ enum BitField {
other
}
fn example_enum_as_bitfield_use() {
fn main() {
assert 1 == int(BitField.read)
assert 2 == int(BitField.write)
mut bf := BitField.read
assert bf.has(.read | .other) // test if *at least one* of the flags is set
assert !bf.all(.read | .other) // test if *all* of the flags is set
bf.set(.write | .other)
assert bf.has(.read | .write | .other)
assert bf.all(.read | .write | .other)
bf.toggle(.other)
assert bf == BitField.read | .write
assert bf.all(.read | .write)
assert !bf.has(.other)
}
```
```v
// Calling this function will result in a deprecation warning
[deprecated]
fn old_function() {
@@ -5372,7 +5381,9 @@ fn legacy_function() {}
[deprecated: 'use new_function2() instead']
[deprecated_after: '2021-05-27']
fn legacy_function2() {}
```
```v nofmt
// This function's calls will be inlined.
[inline]
fn inlined_function() {