36 lines
1.0 KiB
Plaintext
36 lines
1.0 KiB
Plaintext
:sig
|
|
bool DValue::is_list() const
|
|
|
|
:params
|
|
return value : true when the node is a sequential, numerically indexed container
|
|
|
|
:see
|
|
>types
|
|
0_DValue
|
|
is_array
|
|
push
|
|
each
|
|
dv_values
|
|
|
|
:content
|
|
Tests whether a map-shaped `DValue` represents a list: its keys are the numeric strings `"0"`, `"1"`, `"2"`, ... in unbroken sequence. This is a read accessor: it is `const`, never creates or modifies nodes, and dereferences internal references automatically.
|
|
|
|
Containers built with `push()` are lists. An empty container counts as a list when it was created with `set_array()` or `push()`; a keyed map (or a map with gaps in its numeric keys) is `is_array()` but not `is_list()`.
|
|
|
|
```cpp
|
|
DValue items;
|
|
items.push(first_item);
|
|
items.push(second_item);
|
|
// items.is_list() == true
|
|
|
|
items["custom"] = "x";
|
|
// items.is_list() == false, items.is_array() == true
|
|
```
|
|
|
|
`dv_map()` and `dv_filter()` use this distinction: list inputs re-index from zero, while map inputs keep their original keys.
|
|
|
|
## Related Concepts
|
|
|
|
- PHP: `array_is_list()`
|
|
- JavaScript: `Array.isArray()`
|