Defined in header <fkYAML/node.hpp>
fkyaml::basic_node::(constructor)¶
basic_node() = default; // (1)
explicit basic_node(const node_type type); // (2)
explicit basic_node(const node_t type); // (3) deprecated
basic_node(const basic_node& rhs); // (4)
basic_node(basic_node&& rhs) noexcept; // (5)
template <
typename CompatibleType, typename U = detail::remove_cv_ref_t<CompatibleType>,
detail::enable_if_t<
detail::conjunction<
detail::negation<detail::is_basic_json<U>>,
detail::disjunction<detail::is_node_compatible_type<basic_node, U>>>::value,
int> = 0>
basic_node(CompatibleType&& val) noexcept(
noexcept(ConverterType<U>::to_node(std::declval<basic_node&>(), std::declval<CompatibleType>()))); // (6)
template <
typename NodeRefStorageType,
detail::enable_if_t<detail::is_node_ref_storage<NodeRefStorageType>::value, int> = 0>
basic_node(const NodeRefStorageType& node_ref_storage) noexcept; // (7)
basic_node(initializer_list_t init); // (8)
Constructs a new basic_node from a variety of data sources.
Available overloads are described down below.
Overload (1)¶
Default constructor. Constructs a basic_node with a null value.The resulting basic_node has the
node_t::NULL_OBJECT
type.
Example
#include <iostream>
#include <fkYAML/node.hpp>
int main() {
fkyaml::node n;
std::cout << n << std::endl;
return 0;
}
output:
Overload (2)¶
Constructs a basic_node with the given type.The resulting basic_node has a default value for the given type.
Parameters¶
type
[in]- A YAML node type.
Example
#include <iostream>
#include <fkYAML/node.hpp>
int main() {
fkyaml::node n(fkyaml::node_type::INTEGER);
std::cout << n << std::endl;
return 0;
}
output:
Overload (3)¶
Deprecation
The constructor basic_node(const node_type)
replaces the constructor basic_node(const node_t)
which has been deprecated in version 0.3.12. It will be removed in version 0.4.0. Please replace calls like
with
Constructs a basic_node with the given type.
The resulting basic_node has a default value for the given type.
Parameters¶
type
[in]- A YAML node type.
Example
#include <iostream>
#include <fkYAML/node.hpp>
int main() {
fkyaml::node n(fkyaml::node::node_t::INTEGER);
std::cout << n << std::endl;
return 0;
}
output:
Overload (4)¶
Copy constructor. Copies the internal data ofrhs
into the resulting basic_node.The resulting basic_node has the same type and value as
rhs
.
Parameters¶
rhs
[in]- A basic_node object to be copied with.
Example
#include <iostream>
#include <fkYAML/node.hpp>
int main() {
fkyaml::node n(fkyaml::node::node_t::BOOLEAN);
fkyaml::node n2(n);
std::cout << n2 << std::endl;
return 0;
}
output:
Overload (5)¶
Move constructor. Move the internal data ofrhs
into the resulting basic_node.The resulting basic_node has the same type and value as
rhs
.The value of the argument
rhs
after calling this move constructor, will be the same as a default-constructed basic_node.
Parameters¶
rhs
[in]- A basic_node object to be moved from.
Example
#include <iostream>
#include <fkYAML/node.hpp>
int main() {
fkyaml::node n(fkyaml::node::node_t::BOOLEAN);
fkyaml::node n2(std::move(n));
std::cout << n2 << std::endl;
return 0;
}
output:
Overload (6)¶
template <
typename CompatibleType, typename U = detail::remove_cv_ref_t<CompatibleType>,
detail::enable_if_t<
detail::conjunction<
detail::negation<detail::is_basic_json<U>>,
detail::disjunction<detail::is_node_compatible_type<basic_node, U>>>::value,
int> = 0>
basic_node(CompatibleType&& val) noexcept(
noexcept(ConverterType<U>::to_node(std::declval<basic_node&>(), std::declval<CompatibleType>()))); // (5)
The resulting basic_node has the value of
val
and the type which is associated with CompatibleType
.
Template Parameters¶
CompatibleType
- Type of native data which is compatible with node values.
U
- Type of compatible native data without cv-qualifiers and reference.
Parameters¶
val
[in]- The value of a compatible type.
Example
#include <iostream>
#include <fkYAML/node.hpp>
int main() {
double pi = 3.141592;
fkyaml::node n = pi;
std::cout << n << std::endl;
return 0;
}
output:
Overload (7)¶
template <
typename NodeRefStorageType,
detail::enable_if_t<detail::is_node_ref_storage<NodeRefStorageType>::value, int> = 0>
basic_node(const NodeRefStorageType& node_ref_storage) noexcept;
The resulting basic_node has the value of the referenced basic_node by
node_ref_storage
.
Warning
This constructor is mainly for the one with std::initializer_list, and the argument type is too detailed to be used from outside the fkYAML library.
So, this overload might become unavailable in the future major version.
Please refrain from intentionally using this overload, and use the overload with std::initializer_list instead.
Template Parameters¶
NodeRefStorageType
- Type of basic_node with reference.
Parameters¶
node_ref_storage
[in]- A node_ref_storage template class object.
Example
#include <iostream>
#include <fkYAML/node.hpp>
int main() {
fkyaml::node n({true, false});
std::cout << n << std::endl;
return 0;
}
output:
Overload (8)¶
Constructs a basic_node with a initializer_list_t object.The resulting basic_node has the value of a container (sequence or mapping) which has the contents of
init
.Basically, the basic_node objects in
init
are considered as a sequence node.
If init
contains a sequence of basic_node objects in which the number of basic_node objects is 2 and the first has the type of node_t::STRING
, however, such a sequence is reinterpreted as a mapping node.
Parameters¶
init
[in]- A initializer list of basic_node objects.
Example
#include <iostream>
#include <fkYAML/node.hpp>
int main() {
fkyaml::node n = {true, false};
std::cout << n << std::endl;
fkyaml::node n2 = {{"foo", 1024}};
std::cout << n2 << std::endl;
return 0;
}
output: