Skip to content

Defined in header <fkYAML/node.hpp>

fkyaml::literals::yaml_literals::operator"" _yaml

inline node operator"" _yaml(const char* s, std::size_t n);
inline node operator"" _yaml(const char8_t* s, std::size_t n); // for C++20 or better
inline node operator"" _yaml(const char16_t* s, std::size_t n);
inline node operator"" _yaml(const char32_t* s, std::size_t n);

This operator implements a user-defined string literal for YAML node objects.
It can be used by adding _yaml to a string literal encoded in either UTF-8, UTF-16 or UTF-32 format and returns a node object if no error occured in the deserialization process.
Calling this operator is equivalent with calling fkyaml::basic_node::deserialize(s, s + n).

This operator is declared in the namespace fkyaml::literals::yaml_literals, where both literals and yaml_literals are inline namespaces.
Access to this operator can be gained with:

  • using namespace fkyaml::literals;,
  • using namespace fkyaml::yaml_literals;, or
  • using namespace fkyaml::literals::yaml_literals;

Parameters

s [in]
A string representation of a YAML node object.
char or char8_t(for C++20 or better), char16_t and char32_t are interpreted as the UTF-8, UTF-16 and UTF-32 encodings, respectively.
n [in]
The length of the string s.

Return Value

The resulting basic_node object deserialized from the input string s.

Example
#include <iostream>
#include <fkYAML/node.hpp>

int main() {
    // bring the user-defined literals into this scope.
    using namespace fkyaml::literals::yaml_literals;

    // deserialize a YAML string encoded in the UTF-8 format.
    fkyaml::node n_u8 = u8"foo: bar"_yaml;
    std::cout << n_u8 << std::endl;

    // deserialize a YAML string encoded in the UTF-16 format.
    fkyaml::node n_u16 = u"foo: bar"_yaml;
    std::cout << n_u16 << std::endl;

    // deserialize a YAML string encoded in the UTF-32 format.
    fkyaml::node n_u32 = U"foo: bar"_yaml;
    std::cout << n_u32 << std::endl;

    return 0;
}

output:

foo: bar

foo: bar

foo: bar

See Also