Код: Выделить всё
string keyPath("a.b.c");
vector keyPieces(split(keyPath, "."));
const YAML::Node *currNode = &rootNode;
for_each(begin(keyPieces), end(keyPieces), [&](const string &key)
{
// for simplicity, ignore indexing on a possible scalar node
// and using a string index on a sequence node
if ((*currNode)[key])
{
currNode = &((*currNode)[key]);
}
});
// assuming a valid path, currNode should be pointing at the node
// described in the path (i.e. currNode is pointing at the "c" node)
Код: Выделить всё
currNode = currNode[key]
Код: Выделить всё
currNode = &((*currNode)[key])
Есть ли «более чистый» или более идиоматический способ добиться этого?
Подробнее здесь: https://stackoverflow.com/questions/146 ... -reference