Defined in header <fkYAML/node.hpp>
fkyaml::basic_node::swap¶
void swap(basic_node& rhs) noexcept; // (1)
template <
template <typename, typename...> class SequenceType, template <typename, typename, typename...> class MappingType,
typename BooleanType, typename IntegerType, typename FloatNumberType, typename StringType,
template <typename, typename = void> class ConverterType>
inline void swap(
basic_node<SequenceType, MappingType, BooleanType, IntegerType, FloatNumberType, StringType, ConverterType>& lhs,
basic_node<SequenceType, MappingType, BooleanType, IntegerType, FloatNumberType, StringType, ConverterType>& rhs) noexcept(noexcept(lhs.swap(rhs))); // (2) non-member function
Swaps the internally stored data with the given basic_node object.
Parameters¶
lhs
[in, out]- A basic_node to swap the contents with.
rhs
[in, out]- A basic_node to swap the contents with.
member function: Swap the contents with another basic_node
#include <iostream>
#include <fkYAML/node.hpp>
int main() {
// create YAML nodes.
fkyaml::node n1 = 123;
fkyaml::node n2 = "foo";
// swap the internally stored data between n1 & n2.
n1.swap(n2);
// print the swapped values.
std::cout << n1.as_str() << std::endl;
std::cout << n2.get_value<std::int64_t>() << std::endl;
return 0;
}
output:
Examples¶
non-member function: Swap the contents between basic_node objects
#include <iostream>
#include <fkYAML/node.hpp>
int main() {
// create YAML nodes.
fkyaml::node n1 = 123;
fkyaml::node n2 = "foo";
// swap the internally stored data between n1 & n2.
using std::swap;
swap(n1, n2);
// print the swapped values.
std::cout << n1.as_str() << std::endl;
std::cout << n2.get_value<std::int64_t>() << std::endl;
return 0;
}
output: