Skip to content

is_val/has_val #228

Answered by biojppm
Beliar83 asked this question in Q&A
Mar 16, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

To clarify:

  • has_val() if it has a val regardless of having a key, so it is true both for sequence and map members
  • is_val() if it has a val and does NOT have a key, so it is true only for sequence members

Here's the relevant code:

Eg:

seq:
  - val0
  - val1
map:
  key0: val0
  key1: val1

Then the following holds:

assert( ! tree["seq"].has_val()); // it's a container, so it does not have a val
assert( ! tree["map"].has_val()); // it's a container, so it does not have a val

assert(   tree["seq"][0].has_val());
assert(   tree["seq"][1].has_val());
assert(   tree["seq"][0].is_val());
assert(   tree["seq"][1].is_val());

assert(   tree["map"][0].has_val());
assert(   tree["map"][1].has_val(…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Beliar83
Comment options

Answer selected by Beliar83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants