rapidyaml 0.15.2
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
Static trees

Functions

void sample_static_trees ()
 how to use static trees in ryml

Detailed Description

Function Documentation

◆ sample_static_trees()

void sample_static_trees ( )

how to use static trees in ryml

shows how to work around the static initialization order fiasco when using a static-duration ryml tree

See also
https://en.cppreference.com/w/cpp/language/siof

Definition at line 6992 of file quickstart.cpp.

6993{
6994 // Static trees may incur a static initialization order
6995 // problem. This happens because a default-constructed tree will
6996 // obtain the callbacks from the current global setting, which may
6997 // not have been initialized due to undefined static
6998 // initialization order:
6999 //
7000 // ERROR! depends on ryml::get_callbacks() which may not have been initialized.
7001 //static ryml::Tree tree;
7002 //
7003 // To work around the issue, declare static callbacks
7004 // to explicitly initialize the static tree:
7005 static ryml::Callbacks callbacks = default_callbacks(); // use default callback members
7006 static ryml::Tree tree(callbacks); // OK
7007 // now you can use the tree as normal:
7008 ryml::parse_in_arena(R"(doe: "a deer, a female deer")", &tree);
7009 CHECK(tree["doe"].val() == "a deer, a female deer");
7010}
void parse_in_arena(Parser *parser, csubstr filename, csubstr yaml, Tree *tree, id_type node_id)
(1) parse YAML into an existing tree node. The filename will be used in any error messages arising du...
Definition parse.cpp:209
ryml::Callbacks default_callbacks()
set up a bare-bones implementation of the callbacks
#define CHECK(predicate)
a testing assertion, used only in this quickstart
A c-style callbacks class to customize behavior on errors or allocation.
Definition common.hpp:374

Referenced by main().