template <typename ValueType>
toml::value class final

A TOML value.

Template parameters
ValueType

The value's native TOML data type. Can be one of:

Base classes

class node
A TOML node.

Public types

using value_arg = std::conditional_t<std::is_same_v<value_type, std::string>, std::string_view, std::conditional_t<impl::is_one_of<value_type, double, int64_t, bool>, value_type, const value_type&>>
A type alias for 'value arguments'.
using value_type = ValueType
The value's underlying data type.

Constructors, destructors, conversion operators

template <typename... Args>
value(Args && ... args) explicit noexcept(…)
Constructs a toml value.
value(const value& other) noexcept
Copy constructor.
value(value&& other) noexcept
Move constructor.

Public functions

auto operator=(const value& rhs) -> value& noexcept
Copy-assignment operator.
auto operator=(value&& rhs) -> value& noexcept
Move-assignment operator.
auto operator=(value_arg rhs) -> value& noexcept
Value-assignment operator.

Equality

template <typename T>
auto operator!=(const value& lhs, const value<T>& rhs) -> bool noexcept
Inequality operator.
auto operator<(const value& lhs, value_arg rhs) -> bool noexcept
Value less-than operator.
auto operator<(value_arg lhs, const value& rhs) -> bool noexcept
Value less-than operator.
template <typename T>
auto operator<(const value& lhs, const value<T>& rhs) -> bool noexcept
Less-than operator.
auto operator<=(const value& lhs, value_arg rhs) -> bool noexcept
Value less-than-or-equal-to operator.
auto operator<=(value_arg lhs, const value& rhs) -> bool noexcept
Value less-than-or-equal-to operator.
template <typename T>
auto operator<=(const value& lhs, const value<T>& rhs) -> bool noexcept
Less-than-or-equal-to operator.
auto operator==(const value& lhs, value_arg rhs) -> bool noexcept
Value equality operator.
template <typename T>
auto operator==(const value& lhs, const value<T>& rhs) -> bool noexcept
Equality operator.
auto operator>(const value& lhs, value_arg rhs) -> bool noexcept
Value greater-than operator.
auto operator>(value_arg lhs, const value& rhs) -> bool noexcept
Value greater-than operator.
template <typename T>
auto operator>(const value& lhs, const value<T>& rhs) -> bool noexcept
Greater-than operator.
auto operator>=(const value& lhs, value_arg rhs) -> bool noexcept
Value greater-than-or-equal-to operator.
auto operator>=(value_arg lhs, const value& rhs) -> bool noexcept
Value greater-than-or-equal-to operator.
template <typename T>
auto operator>=(const value& lhs, const value<T>& rhs) -> bool noexcept
Greater-than-or-equal-to operator.

Metadata

auto flags() const -> value_flags noexcept
Returns the metadata flags associated with this value.
auto flags(value_flags new_flags) -> value& noexcept
Sets the metadata flags associated with this value.
auto source() const -> const source_region& noexcept
Returns the source region responsible for generating this node during parsing.

Node views

operator node_view<const node>() const explicit noexcept
Creates a node_view pointing to this node (const overload).
operator node_view<node>() explicit noexcept
Creates a node_view pointing to this node.

Type casts

template <typename T>
auto as() -> impl::wrap_node<T>* noexcept
Gets a pointer to the node as a more specific node type.
template <typename T>
auto as() const -> const impl::wrap_node<T>* noexcept
Gets a pointer to the node as a more specific node type (const overload).
auto as_array() -> array* virtual noexcept
Returns a pointer to the node as a toml::array, if it is one.
auto as_boolean() -> value<bool>* override noexcept
Returns a pointer to the node as a toml::value<bool>, if it is one.
auto as_date() -> value<date>* override noexcept
Returns a pointer to the node as a toml::value<date>, if it is one.
auto as_date_time() -> value<date_time>* override noexcept
Returns a pointer to the node as a toml::value<date_time>, if it is one.
auto as_floating_point() -> value<double>* override noexcept
Returns a pointer to the node as a toml::value<double>, if it is one.
auto as_integer() -> value<int64_t>* override noexcept
Returns a pointer to the node as a toml::value<int64_t>, if it is one.
auto as_string() -> value<std::string>* override noexcept
Returns a pointer to the node as a toml::value<string>, if it is one.
auto as_table() -> table* virtual noexcept
Returns a pointer to the node as a toml::table, if it is one.
auto as_time() -> value<time>* override noexcept
Returns a pointer to the node as a toml::value<time>, if it is one.

Type checks

template <typename T>
auto is() const -> bool noexcept
Checks if a node is a specific type.
auto is_array() const -> bool override noexcept
Returns true if this node is an array.
auto is_array_of_tables() const -> bool virtual noexcept
Returns true if this node is an array containing only tables.
auto is_boolean() const -> bool override noexcept
Returns true if this node is a boolean value.
auto is_date() const -> bool override noexcept
Returns true if this node is a local date value.
auto is_date_time() const -> bool override noexcept
Returns true if this node is a date-time value.
auto is_floating_point() const -> bool override noexcept
Returns true if this node is an floating-point value.
auto is_homogeneous(node_type ntype) const -> bool override noexcept
Checks if the node contains values/elements of only one type.
auto is_homogeneous(node_type ntype, toml::node*& first_nonmatch) -> bool override noexcept
Checks if a node contains values/elements of only one type.
auto is_homogeneous(node_type ntype, const toml::node*& first_nonmatch) const -> bool override noexcept
Checks if a node contains values/elements of only one type (const overload).
auto is_integer() const -> bool override noexcept
Returns true if this node is an integer value.
auto is_number() const -> bool override noexcept
Returns true if this node is an integer or floating-point value.
auto is_string() const -> bool override noexcept
Returns true if this node is a string value.
auto is_table() const -> bool override noexcept
Returns true if this node is a table.
auto is_time() const -> bool override noexcept
Returns true if this node is a local time value.
auto is_value() const -> bool override noexcept
Returns true if this node is a value.
auto type() const -> node_type override noexcept
Returns the value's node type identifier.

Value retrieval

auto get() & -> value_type& noexcept
Returns a reference to the underlying value.
auto get() && -> value_type&& noexcept
Returns a reference to the underlying value (rvalue overload).
auto get() const & -> const value_type& noexcept
Returns a reference to the underlying value (const overload).
operator const value_type&() const & explicit noexcept
Returns a reference to the underlying value (const overload).
operator value_type&() & explicit noexcept
Returns a reference to the underlying value.
operator value_type&&() && explicit noexcept
Returns a reference to the underlying value (rvalue overload).
auto operator*() & -> value_type& noexcept
Returns a reference to the underlying value.
auto operator*() && -> value_type&& noexcept
Returns a reference to the underlying value (rvalue overload).
auto operator*() const & -> const value_type& noexcept
Returns a reference to the underlying value (const overload).
template <typename T>
auto ref() & -> impl::unwrap_node<T>& noexcept
Gets a raw reference to a value node's underlying data.
template <typename T>
auto ref() && -> impl::unwrap_node<T>&& noexcept
Gets a raw reference to a value node's underlying data (rvalue overload).
template <typename T>
auto ref() const & -> const impl::unwrap_node<T>& noexcept
Gets a raw reference to a value node's underlying data (const lvalue overload).
template <typename T>
auto value() const -> optional<T> noexcept
Gets the value contained by this node.
template <typename T>
auto value_exact() const -> optional<T> noexcept
Gets the value contained by this node.
template <typename T>
auto value_or(T&& default_value) const -> auto noexcept
Gets the raw value contained by this node, or a default.

Visitation

template <typename Func>
auto visit(Func&& visitor) & -> decltype(auto) noexcept(…)
Invokes a visitor on the node based on the node's concrete type.
template <typename Func>
auto visit(Func&& visitor) && -> decltype(auto) noexcept(…)
Invokes a visitor on the node based on the node's concrete type (rvalue overload).
template <typename Func>
auto visit(Func&& visitor) const & -> decltype(auto) noexcept(…)
Invokes a visitor on the node based on the node's concrete type (const lvalue overload).

Friends

template <typename Char, typename T>
auto operator<<(std::basic_ostream<Char>& lhs, const value<T>& rhs) -> std::basic_ostream<Char>&
Prints the value out to a stream as formatted TOML.

Typedef documentation

template <typename ValueType>
using toml::value::value_arg = std::conditional_t<std::is_same_v<value_type, std::string>, std::string_view, std::conditional_t<impl::is_one_of<value_type, double, int64_t, bool>, value_type, const value_type&>>

A type alias for 'value arguments'.

This differs according to the value's type argument:

  • ints, floats, booleans: value_type
  • strings: string_view
  • everything else: const value_type&

Function documentation

template <typename ValueType>
template <typename... Args>
toml::value::value(Args && ... args) explicit noexcept(…)

Constructs a toml value.

Template parameters
Args Constructor argument types.
Parameters
args Arguments to forward to the internal value's constructor.

template <typename ValueType>
template <typename T>
bool toml::value::operator!=(const value& lhs, const value<T>& rhs) noexcept

Inequality operator.

Parameters
lhs The LHS value.
rhs The RHS value.
Returns True if the values were not of the same type, or did not contain the same value.

template <typename ValueType>
template <typename T>
bool toml::value::operator<(const value& lhs, const value<T>& rhs) noexcept

Less-than operator.

Parameters
lhs The LHS toml::value.
rhs The RHS toml::value.
Returns Same value types: lhs.get() < rhs.get()Different value types: lhs.type() < rhs.type()

template <typename ValueType>
template <typename T>
bool toml::value::operator<=(const value& lhs, const value<T>& rhs) noexcept

Less-than-or-equal-to operator.

Parameters
lhs The LHS toml::value.
rhs The RHS toml::value.
Returns Same value types: lhs.get() <= rhs.get()Different value types: lhs.type() <= rhs.type()

template <typename ValueType>
template <typename T>
bool toml::value::operator==(const value& lhs, const value<T>& rhs) noexcept

Equality operator.

Parameters
lhs The LHS value.
rhs The RHS value.
Returns True if the values were of the same type and contained the same value.

template <typename ValueType>
template <typename T>
bool toml::value::operator>(const value& lhs, const value<T>& rhs) noexcept

Greater-than operator.

Parameters
lhs The LHS toml::value.
rhs The RHS toml::value.
Returns Same value types: lhs.get() > rhs.get()Different value types: lhs.type() > rhs.type()

template <typename ValueType>
template <typename T>
bool toml::value::operator>=(const value& lhs, const value<T>& rhs) noexcept

Greater-than-or-equal-to operator.

Parameters
lhs The LHS toml::value.
rhs The RHS toml::value.
Returns Same value types: lhs.get() >= rhs.get()Different value types: lhs.type() >= rhs.type()

template <typename ValueType>
value& toml::value::flags(value_flags new_flags) noexcept

Sets the metadata flags associated with this value.

Returns A reference to the value object.

template <typename ValueType>
bool toml::value::is_homogeneous(node_type ntype) const override noexcept

Checks if the node contains values/elements of only one type.

Parameters
ntype A TOML node type.
toml::node_type::none: "is every element the same type?" Anything else: "is every element one of these?"
Returns True if the node was homogeneous.
auto arr = toml::array{ 1, 2, 3 };
std::cout << "homogenous: "sv << arr.is_homogeneous(toml::node_type::none) << "\n";
std::cout << "all floats: "sv << arr.is_homogeneous(toml::node_type::floating_point) << "\n";
std::cout << "all arrays: "sv << arr.is_homogeneous(toml::node_type::array) << "\n";
std::cout << "all ints:   "sv << arr.is_homogeneous(toml::node_type::integer) << "\n";
homogeneous: true
all floats:  false
all arrays:  false
all ints:    true

template <typename ValueType>
bool toml::value::is_homogeneous(node_type ntype, toml::node*& first_nonmatch) override noexcept

Checks if a node contains values/elements of only one type.

Parameters
ntype A TOML node type.
toml::node_type::none: "is every element the same type?" Anything else: "is every element one of these?"
first_nonmatch Reference to a pointer in which the address of the first non-matching element will be stored if the return value is false.
Returns True if the node was homogeneous.
auto cfg = toml::parse("arr = [ 1, 2, 3, 4.0 ]");
toml::array& arr = *cfg["arr"].as_array();

toml::node* nonmatch{};
if (arr.is_homogeneous(toml::node_type::integer, nonmatch))
    std::cout << "array was homogeneous"sv << "\n";
else
    std::cout << "array was not homogeneous!\n"
    << "first non-match was a "sv << nonmatch->type() << " at " << nonmatch->source() << "\n";
array was not homogeneous!
first non-match was a floating-point at line 1, column 18

template <typename ValueType>
node_type toml::value::type() const override noexcept

Returns the value's node type identifier.

Returns

One of: