37 lines
1003 B
Plaintext
37 lines
1003 B
Plaintext
:sig
|
|
bool DValue::has(String s) const
|
|
|
|
:params
|
|
s : child key to test
|
|
return value : true when the node is map-shaped and contains the key
|
|
|
|
:see
|
|
>types
|
|
0_DValue
|
|
get_by_path
|
|
each
|
|
is_array
|
|
|
|
:content
|
|
Tests whether a map-shaped `DValue` contains a child key, without creating it. This is a read accessor: it is `const`, never creates or modifies nodes, and dereferences internal references automatically.
|
|
|
|
Returns `false` for scalar nodes and for missing keys.
|
|
|
|
This matters because `operator[]` creates missing entries, exactly like `std::map`. Use `has()` (or `get_by_path()`) when you only want to look:
|
|
|
|
```cpp
|
|
if(context.props.has("avatar"))
|
|
print(component("components/basic/avatar", context.props["avatar"], context));
|
|
```
|
|
|
|
`has()` only checks one level. For nested checks, combine with `get_by_path()`:
|
|
|
|
```cpp
|
|
bool configured = context.cfg.get_by_path("mail/smtp").is_array();
|
|
```
|
|
|
|
## Related Concepts
|
|
|
|
- PHP: `array_key_exists()` / `isset()`
|
|
- JavaScript: `Object.hasOwn(obj, key)` / `key in obj`
|