rapidyaml 0.16.0
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 7076 of file quickstart.cpp.

7077{
7078 // Static trees may incur a static initialization order
7079 // problem. This happens because a default-constructed tree will
7080 // obtain the callbacks from the current global setting, which may
7081 // not have been initialized due to undefined static
7082 // initialization order:
7083 //
7084 // ERROR! depends on ryml::get_callbacks() which may not have been initialized.
7085 //static ryml::Tree tree;
7086 //
7087 // To work around the issue, declare static callbacks
7088 // to explicitly initialize the static tree:
7089 static ryml::Callbacks callbacks = default_callbacks(); // use default callback members
7090 static ryml::Tree tree(callbacks); // OK
7091 // now you can use the tree as normal:
7092 ryml::parse_in_arena(R"(doe: "a deer, a female deer")", &tree);
7093 CHECK(tree["doe"].val() == "a deer, a female deer");
7094}
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().