0

Example from boost tutorial:

using namespace fields;
std::string person_name = at_key<name>(a_person);
int person_age = at_key<age>(a_person);

How to check wheather there is no such key in this map?

vitperov
  • 1,347
  • 17
  • 20

1 Answers1

1

To check if a given sequence contains an element associated with a given Key, one can (and should) use has_key<Key> (seq), as in the below example.

if (has_key<fields::age> (some_seq)) {
  int person_age = at_key<fields::age> (some_seq);
}

Documentation:

Community
  • 1
  • 1
Filip Roséen - refp
  • 62,493
  • 20
  • 150
  • 196