class
tableA TOML table.
The interface of this type is modeled after std::
toml::table tbl = toml::parse(R"( [animals] cats = [ "tiger", "lion", "puma" ] birds = [ "macaw", "pigeon", "canary" ] fish = [ "salmon", "trout", "carp" ] )"sv); // operator[] retrieves node-views std::cout << "cats: " << tbl["animals"]["cats"] << "\n"; std::cout << "fish[1]: " << tbl["animals"]["fish"][1] << "\n"; // at_path() does fully-qualified "toml path" lookups std::cout << "cats: " << tbl.at_path("animals.cats") << "\n"; std::cout << "fish[1]: " << tbl.at_path("animals.fish[1]") << "\n";
cats: ['tiger', 'lion', 'puma'] fish[1] : 'trout' cats : ['tiger', 'lion', 'puma'] fish[1] : 'trout'
Base classes
- class node
- A TOML node.
Constructors, destructors, conversion operators
Public functions
Equality
- auto operator!=(const table& lhs, const table& rhs) → bool noexcept
- Inequality operator.
- auto operator==(const table& lhs, const table& rhs) → bool noexcept
- Equality operator.
Erasure
- void clear() noexcept
- Removes all key-value pairs from the table.
- auto erase(iterator pos) → iterator noexcept
- Removes the specified key-value pair from the table.
-
auto erase(const_
iterator pos) → iterator noexcept - Removes the specified key-value pair from the table (const iterator overload).
-
auto erase(const_
iterator begin, const_ iterator end) → iterator noexcept - Removes the key-value pairs in the range [first, last) from the table.
-
auto erase(std::
string_view key) → size_t noexcept - Removes the value with the given key from the table.
-
auto erase(std::
wstring_view key) → size_t - Removes the value with the given key from the table.
- auto prune(bool recursive = true) & → table& noexcept
- Removes empty child arrays and tables.
- auto prune(bool recursive = true) && → table&& noexcept
- Removes empty child arrays and tables (rvalue overload).
Insertion and Emplacement
-
template <typename ValueType, typename KeyType, typename... ValueArgs>auto emplace(KeyType&& key, ValueArgs && ... args) → std::
pair<iterator, bool> - Emplaces a new value at a specific key if one did not already exist.
-
template <typename ValueType, typename KeyType, typename... ValueArgs>auto emplace_hint(const_
iterator hint, KeyType&& key, ValueArgs && ... args) → iterator - Emplaces a new value at a specific key if one did not already exist.
-
template <typename KeyType, typename ValueType>auto insert(KeyType&& key, ValueType&& val, value_
flags flags = preserve_ source_ value_ flags) → std:: pair<iterator, bool> - Inserts a new value at a specific key if one did not already exist.
-
template <typename Iter>void insert(Iter begin, Iter end, value_
flags flags = preserve_ source_ value_ flags) - Inserts a series of key-value pairs into the table.
-
template <typename KeyType, typename ValueType>auto insert_or_assign(KeyType&& key, ValueType&& val, value_
flags flags = preserve_ source_ value_ flags) → std:: pair<iterator, bool> - Inserts or assigns a value at a specific key.
Iterators
-
using const_iterator = toml::
const_table_iterator - A BidirectionalIterator for iterating over const key-value pairs in a toml::
table. -
using iterator = toml::
table_iterator - A BidirectionalIterator for iterating over key-value pairs in a toml::
table. - auto begin() → iterator noexcept
- Returns an iterator to the first key-value pair.
-
auto begin() const → const_
iterator noexcept - Returns an iterator to the first key-value pair.
-
auto cbegin() const → const_
iterator noexcept - Returns an iterator to the first key-value pair.
-
auto cend() const → const_
iterator noexcept - Returns an iterator to one-past-the-last key-value pair.
- auto end() → iterator noexcept
- Returns an iterator to one-past-the-last key-value pair.
-
auto end() const → const_
iterator noexcept - Returns an iterator to one-past-the-last key-value pair.
Metadata
- auto is_inline() const → bool noexcept
- Returns true if this table is an inline table.
- void is_inline(bool val) noexcept
- Sets whether this table is a TOML inline table.
-
auto source() const → const source_
region& noexcept - Returns the source region responsible for generating this node during parsing.
Node views
-
auto at_path(std::
string_view path) → node_ view<node> noexcept - Returns a view of the subnode matching a fully-qualified "TOML path".
-
auto at_path(std::
string_view path) const → node_ view<const node> noexcept - Returns a const view of the subnode matching a fully-qualified "TOML path".
-
auto at_path(std::
wstring_view path) → node_ view<node> - Returns a view of the subnode matching a fully-qualified "TOML path".
-
auto at_path(std::
wstring_view path) const → node_ view<const node> - Returns a const view of the subnode matching a fully-qualified "TOML path".
- 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. -
auto operator[](std::
string_view key) → node_ view<node> noexcept - Gets a node_
view for the selected value. -
auto operator[](std::
string_view key) const → node_ view<const node> noexcept - Gets a node_
view for the selected value (const overload). -
auto operator[](std::
wstring_view key) → node_ view<node> noexcept - Gets a node_
view for the selected value. -
auto operator[](std::
wstring_view key) const → node_ view<const node> noexcept - Gets a node_
view for the selected value (const overload).
Searching
-
auto contains(std::
string_view key) const → bool noexcept - Returns true if the table contains a node at the given key.
-
auto contains(std::
wstring_view key) const → bool - Returns true if the table contains a node at the given key.
-
auto find(std::
string_view key) → iterator noexcept - Gets an iterator to the node at a specific key.
-
auto find(std::
string_view key) const → const_ iterator noexcept - Gets an iterator to the node at a specific key (const overload)
-
auto find(std::
wstring_view key) → iterator - Gets an iterator to the node at a specific key.
-
auto find(std::
wstring_view key) const → const_ iterator - Gets an iterator to the node at a specific key (const overload).
-
auto lower_bound(std::
string_view key) → iterator noexcept - Returns an iterator to the first key-value pair with key that is not less than the given key.
-
auto lower_bound(std::
string_view key) const → const_ iterator noexcept - Returns a const iterator to the first key-value pair with key that is not less than the given key.
-
auto lower_bound(std::
wstring_view key) → iterator - Returns an iterator to the first key-value pair with key that is not less than the given key.
-
auto lower_bound(std::
wstring_view key) const → const_ iterator - Returns a const iterator to the first key-value pair with key that is not less than the given key.
Size and Capacity
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* final noexcept
- Returns
nullptr
. - auto as_array() const → const array* final noexcept
- Returns
nullptr
. -
auto as_boolean() → toml::
value<bool>* final noexcept - Returns
nullptr
. -
auto as_boolean() const → const toml::
value<bool>* final noexcept - Returns
nullptr
. -
auto as_date() → toml::
value<date>* final noexcept - Returns
nullptr
. -
auto as_date() const → const toml::
value<date>* final noexcept - Returns
nullptr
. -
auto as_date_time() → toml::
value<date_ time>* final noexcept - Returns
nullptr
. -
auto as_date_time() const → const toml::
value<date_ time>* final noexcept - Returns
nullptr
. -
auto as_floating_point() → toml::
value<double>* final noexcept - Returns
nullptr
. -
auto as_floating_point() const → const toml::
value<double>* final noexcept - Returns
nullptr
. -
auto as_integer() → toml::
value<int64_t>* final noexcept - Returns
nullptr
. -
auto as_integer() const → const toml::
value<int64_t>* final noexcept - Returns
nullptr
. -
auto as_string() → toml::
value<std:: string>* final noexcept - Returns
nullptr
. -
auto as_string() const → const toml::
value<std:: string>* final noexcept - Returns
nullptr
. - auto as_table() → table* final noexcept
- Returns a pointer to the table.
- auto as_table() const → const table* final noexcept
- Returns a const-qualified pointer to the table.
-
auto as_time() → toml::
value<time>* final noexcept - Returns
nullptr
. -
auto as_time() const → const toml::
value<time>* final noexcept - Returns
nullptr
.
Type checks
-
template <typename T>auto is() const → bool noexcept
- Checks if a node is a specific type.
- auto is_array() const → bool final noexcept
- Returns
false
. - auto is_array_of_tables() const → bool final noexcept
- Returns
false
. - auto is_boolean() const → bool final noexcept
- Returns
false
. - auto is_date() const → bool final noexcept
- Returns
false
. - auto is_date_time() const → bool final noexcept
- Returns
false
. - auto is_floating_point() const → bool final noexcept
- Returns
false
. -
auto is_homogeneous(node_
type ntype) const → bool final noexcept - Checks if the node contains values/elements of only one type.
-
auto is_homogeneous(node_
type ntype, node*& first_nonmatch) → bool final noexcept - Checks if a node contains values/elements of only one type.
-
auto is_homogeneous(node_
type ntype, const node*& first_nonmatch) const → bool final noexcept - Checks if a node contains values/elements of only one type (const overload).
-
template <typename ElemType = void>auto is_homogeneous() const → bool noexcept
- Checks if the node contains values/elements of only one type.
- auto is_integer() const → bool final noexcept
- Returns
false
. - auto is_number() const → bool final noexcept
- Returns
false
. - auto is_string() const → bool final noexcept
- Returns
false
. - auto is_table() const → bool final noexcept
- Returns
true
. - auto is_time() const → bool final noexcept
- Returns
false
. - auto is_value() const → bool final noexcept
- Returns
false
. -
auto type() const → node_
type final noexcept - Returns toml::
node_type:: table.
Value retrieval
-
auto at(std::
string_view key) → node& - Gets a reference to the element at a specific key, throwing
std::
if none existed.out_of_range -
auto at(std::
string_view key) const → const node& - Gets a reference to the element at a specific key, throwing
std::
if none existed.out_of_range -
auto at(std::
wstring_view key) → node& - Gets a reference to the element at a specific key, throwing
std::
if none existed.out_of_range -
auto at(std::
wstring_view key) const → const node& - Gets a reference to the element at a specific key, throwing
std::
if none existed.out_of_range -
auto get(std::
string_view key) → node* noexcept - Gets the node at a specific key.
-
auto get(std::
string_view key) const → const node* noexcept - Gets the node at a specific key (const overload).
-
auto get(std::
wstring_view key) → node* - Gets the node at a specific key.
-
auto get(std::
wstring_view key) const → const node* - Gets the node at a specific key (const overload).
-
template <typename T>auto get_as(std::
string_view key) → impl::wrap_node<T>* noexcept - Gets the node at a specific key if it is a particular type.
-
template <typename T>auto get_as(std::
string_view key) const → const impl::wrap_node<T>* noexcept - Gets the node at a specific key if it is a particular type (const overload).
-
template <typename T>auto get_as(std::
wstring_view key) → impl::wrap_node<T>* - Gets the node at a specific key if it is a particular type.
-
template <typename T>auto get_as(std::
wstring_view key) const → const impl::wrap_node<T>* - Gets the node at a specific key if it is a particular type (const overload).
-
template <typename T>auto ref() & → decltype(auto) noexcept
- Gets a raw reference to a node's underlying data.
-
template <typename T>auto ref() && → decltype(auto) noexcept
- Gets a raw reference to a node's underlying data (rvalue overload).
-
template <typename T>auto ref() const & → decltype(auto) noexcept
- Gets a raw reference to a node's underlying data (const lvalue overload).
-
template <typename T>auto ref() const && → decltype(auto) noexcept
- Gets a raw reference to a node's underlying data (const rvalue 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).
-
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 rvalue overload).
Friends
-
auto operator<<(std::
ostream& lhs, const table& rhs) → std:: ostream& - Prints the table out to a stream as formatted TOML.
Function documentation
toml:: table:: table(std:: initializer_list<impl::table_init_pair> kvps) explicit
Constructs a table with one or more initial key-value pairs.
Parameters | |
---|---|
kvps | A list of key-value pairs used to initialize the table. |
auto tbl = toml::table{ { "foo", 1 }, { "bar", 2.0 }, { "kek", "three" } }; std::cout << tbl << "\n";
{ foo = 1, bar = 2.0, kek = "three" }
bool toml:: table:: operator!=(const table& lhs,
const table& rhs) noexcept
Inequality operator.
Parameters | |
---|---|
lhs | The LHS table. |
rhs | The RHS table. |
Returns | True if the tables did not contain the same keys and map. |
bool toml:: table:: operator==(const table& lhs,
const table& rhs) noexcept
Equality operator.
Parameters | |
---|---|
lhs | The LHS table. |
rhs | The RHS table. |
Returns | True if the tables contained the same keys and map. |
iterator toml:: table:: erase(iterator pos) noexcept
Removes the specified key-value pair from the table.
Parameters | |
---|---|
pos | Iterator to the key-value pair being erased. |
Returns | Iterator to the first key-value pair immediately following the removed key-value pair. |
auto tbl = toml::table{ { "a", 1 }, { "b", 2 }, { "c", 3 } }; std::cout << tbl << "\n"; tbl.erase(tbl.begin() + 1); std::cout << tbl << "\n";
{ a = 1, b = 2, c = 3 } { a = 1, c = 3 }
iterator toml:: table:: erase(const_ iterator pos) noexcept
Removes the specified key-value pair from the table (const iterator overload).
Parameters | |
---|---|
pos | Iterator to the key-value pair being erased. |
Returns | Iterator to the first key-value pair immediately following the removed key-value pair. |
auto tbl = toml::table{ { "a", 1 }, { "b", 2 }, { "c", 3 } }; std::cout << tbl << "\n"; tbl.erase(tbl.cbegin() + 1); std::cout << tbl << "\n";
{ a = 1, b = 2, c = 3 } { a = 1, c = 3 }
iterator toml:: table:: erase(const_ iterator begin,
const_ iterator end) noexcept
Removes the key-value pairs in the range [first, last) from the table.
Parameters | |
---|---|
begin | Iterator to the first key-value pair being erased. |
end | Iterator to the one-past-the-last key-value pair being erased. |
Returns | Iterator to the first key-value pair immediately following the last removed key-value pair. |
auto tbl = toml::table{ { "a", 1 }, { "b", "bad" }, { "c", "karma" }, { "d", 2 } }; std::cout << tbl << "\n"; tbl.erase(tbl.cbegin() + 1, tbl.cbegin() + 3); std::cout << tbl << "\n";
{ a = 1, b = "bad", c = "karma", d = 2 } { a = 1, d = 2 }
size_t toml:: table:: erase(std:: string_view key) noexcept
Removes the value with the given key from the table.
Parameters | |
---|---|
key | Key to erase. |
Returns | Number of elements removed (0 or 1). |
auto tbl = toml::table{ { "a", 1 }, { "b", 2 }, { "c", 3 } }; std::cout << tbl << "\n"; std::cout << tbl.erase("b") << "\n"; std::cout << tbl.erase("not an existing key") << "\n"; std::cout << tbl << "\n";
{ a = 1, b = 2, c = 3 } true false { a = 1, c = 3 }
size_t toml:: table:: erase(std:: wstring_view key)
Removes the value with the given key from the table.
Parameters | |
---|---|
key | Key to erase. |
Returns | Number of elements removed (0 or 1). |
table& toml:: table:: prune(bool recursive = true) & noexcept
Removes empty child arrays and tables.
Parameters | |
---|---|
recursive | Should child arrays and tables themselves be pruned? |
Returns | A reference to the table. |
auto tbl = toml::table{ { "a", 1 }, { "b", toml::array{ } }, { "c", toml::array{ toml::table{}, toml::array{} } } }; std::cout << arr << "\n"; arr.prune(); std::cout << arr << "\n";
{ a = 1, b = [], c = [ {}, [] ] } { a = 1 }
template <typename ValueType, typename KeyType, typename... ValueArgs>
std:: pair<iterator, bool> toml:: table:: emplace(KeyType&& key,
ValueArgs && ... args)
Emplaces a new value at a specific key if one did not already exist.
Template parameters | |
---|---|
ValueType | toml:: |
KeyType | A toml:: |
ValueArgs | Value constructor argument types. |
Parameters | |
key | The key at which to emplace the new value. |
args | Arguments to forward to the value's constructor. |
Returns | A std::
|
auto tbl = toml::table{ { "a", 1 }, { "b", 2 }, { "c", 3 } }; std::cout << tbl << "\n"; for (auto k : { "a", "d" }) { // add a string using std::string's substring constructor auto result = tbl.emplace<std::string>(k, "this is not a drill"sv, 14, 5); std::cout << "emplaced with key '"sv << k << "': "sv << result.second << "\n"; } std::cout << tbl << "\n";
{ a = 1, b = 2, c = 3 } emplaced with key 'a': false emplaced with key 'd': true { a = 1, b = 2, c = 3, d = "drill" }
template <typename ValueType, typename KeyType, typename... ValueArgs>
iterator toml:: table:: emplace_hint(const_ iterator hint,
KeyType&& key,
ValueArgs && ... args)
Emplaces a new value at a specific key if one did not already exist.
Template parameters | |
---|---|
ValueType | toml:: |
KeyType | A toml:: |
ValueArgs | Value constructor argument types. |
Parameters | |
hint | Iterator to the position before which the new element will be emplaced. |
key | The key at which to emplace the new value. |
args | Arguments to forward to the value's constructor. |
Returns | An iterator to the emplacement position (or the position of the value that prevented emplacement) |
template <typename KeyType, typename ValueType>
std:: pair<iterator, bool> toml:: table:: insert(KeyType&& key,
ValueType&& val,
value_ flags flags = preserve_ source_ value_ flags)
Inserts a new value at a specific key if one did not already exist.
Template parameters | |
---|---|
KeyType | A toml:: |
ValueType | toml:: |
Parameters | |
key | The key at which to insert the new value. |
val | The new value to insert. |
flags | Value flags to apply to new values. |
Returns | Valid input:
Input is a null toml:: |
Try this code on Compiler Explorer
auto tbl = toml::table{ { "a", 1 }, { "b", 2 }, { "c", 3 } }; std::cout << tbl << "\n"; for (auto k : { "a", "d" }) { auto result = tbl.insert(k, 42); std::cout << "inserted with key '"sv << k << "': "sv << result.second << "\n"; } std::cout << tbl << "\n";
a = 1 b = 2 c = 3 inserted with key 'a': false inserted with key 'd': true a = 1 b = 2 c = 3 d = 42
template <typename Iter>
void toml:: table:: insert(Iter begin,
Iter end,
value_ flags flags = preserve_ source_ value_ flags)
Inserts a series of key-value pairs into the table.
Template parameters | |
---|---|
Iter | An InputIterator to a collection of key-value pairs. |
Parameters | |
begin | An iterator to the first value in the input collection. |
end | An iterator to one-past-the-last value in the input collection. |
flags | Value flags to apply to new values. |
Try this code on Compiler Explorer
auto tbl = toml::table{ { "a", 1 }, { "b", 2 }, { "c", 3 } }; std::cout << tbl << "\n"; auto kvps = std::array<std::pair<std::string, int>, 2>{{ { "d", 42 }, { "a", 43 } // won't be inserted, 'a' already exists }}; tbl.insert(kvps.begin(), kvps.end()); std::cout << tbl << "\n";
a = 1 b = 2 c = 3 a = 1 b = 2 c = 3 d = 42
template <typename KeyType, typename ValueType>
std:: pair<iterator, bool> toml:: table:: insert_or_assign(KeyType&& key,
ValueType&& val,
value_ flags flags = preserve_ source_ value_ flags)
Inserts or assigns a value at a specific key.
Template parameters | |
---|---|
KeyType | A toml:: |
ValueType | toml:: |
Parameters | |
key | The key at which to insert or assign the value. |
val | The value to insert/assign. |
flags | Value flags to apply to new values. |
Returns | Valid input:
Input is a null toml:: |
Try this code on Compiler Explorer
auto tbl = toml::table{ { "a", 1 }, { "b", 2 }, { "c", 3 } }; std::cout << tbl << "\n"; for (auto k : { "a", "d" }) { auto result = tbl.insert_or_assign(k, 42); std::cout << "value at key '"sv << k << "' was "sv << (result.second ? "inserted"sv : "assigned"sv) << "\n"; } std::cout << tbl << "\n";
a = 1 b = 2 c = 3 value at key 'a' was assigned value at key 'd' was inserted a = 42 b = 2 c = 3 d = 42
bool toml:: table:: is_inline() const noexcept
Returns true if this table is an inline table.
void toml:: table:: is_inline(bool val) noexcept
Sets whether this table is a TOML inline table.
Parameters | |
---|---|
val | The new value for 'inline'. |
Try this code on Compiler Explorer
auto tbl = toml::table{ { "a", 1 }, { "b", 2 }, { "c", 3 }, { "d", toml::table{ { "e", 4 } } } }; std::cout << "is inline? "sv << tbl.is_inline() << "\n"; std::cout << tbl << "\n\n"; tbl.is_inline(!tbl.is_inline()); std::cout << "is inline? "sv << tbl.is_inline() << "\n"; std::cout << tbl << "\n";
is inline? false a = 1 b = 2 c = 3 [d] e = 4 is inline? true { a = 1, b = 2, c = 3, d = { e = 4 } }
node_ view<node> toml:: table:: operator[](std:: string_view key) noexcept
Gets a node_
Parameters | |
---|---|
key | The key used for the lookup. |
Returns | A view of the value at the given key if one existed, or an empty node view. |
node_ view<const node> toml:: table:: operator[](std:: string_view key) const noexcept
Gets a node_
Parameters | |
---|---|
key | The key used for the lookup. |
Returns | A view of the value at the given key if one existed, or an empty node view. |
node_ view<node> toml:: table:: operator[](std:: wstring_view key) noexcept
Gets a node_
Parameters | |
---|---|
key | The key used for the lookup. |
Returns | A view of the value at the given key if one existed, or an empty node view. |
node_ view<const node> toml:: table:: operator[](std:: wstring_view key) const noexcept
Gets a node_
Parameters | |
---|---|
key | The key used for the lookup. |
Returns | A view of the value at the given key if one existed, or an empty node view. |
bool toml:: table:: contains(std:: wstring_view key) const
Returns true if the table contains a node at the given key.
iterator toml:: table:: find(std:: string_view key) noexcept
Gets an iterator to the node at a specific key.
Parameters | |
---|---|
key | The node's key. |
Returns | An iterator to the node at the specified key, or end(). |
const_ iterator toml:: table:: find(std:: string_view key) const noexcept
Gets an iterator to the node at a specific key (const overload)
Parameters | |
---|---|
key | The node's key. |
Returns | A const iterator to the node at the specified key, or cend(). |
iterator toml:: table:: find(std:: wstring_view key)
Gets an iterator to the node at a specific key.
Parameters | |
---|---|
key | The node's key. |
Returns | An iterator to the node at the specified key, or end(). |
const_ iterator toml:: table:: find(std:: wstring_view key) const
Gets an iterator to the node at a specific key (const overload).
Parameters | |
---|---|
key | The node's key. |
Returns | A const iterator to the node at the specified key, or cend(). |
iterator toml:: table:: lower_bound(std:: string_view key) noexcept
Returns an iterator to the first key-value pair with key that is not less than the given key.
Returns | An iterator to the first matching key-value pair, or end(). |
---|
const_ iterator toml:: table:: lower_bound(std:: string_view key) const noexcept
Returns a const iterator to the first key-value pair with key that is not less than the given key.
Returns | An iterator to the first matching key-value pair, or end(). |
---|
iterator toml:: table:: lower_bound(std:: wstring_view key)
Returns an iterator to the first key-value pair with key that is not less than the given key.
Returns | An iterator to the first matching key-value pair, or end(). |
---|
const_ iterator toml:: table:: lower_bound(std:: wstring_view key) const
Returns a const iterator to the first key-value pair with key that is not less than the given key.
Returns | An iterator to the first matching key-value pair, or end(). |
---|
bool toml:: table:: is_homogeneous(node_ type ntype) const final noexcept
Checks if the node contains values/elements of only one type.
Parameters | |
---|---|
ntype | A TOML node type. toml:: |
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
bool toml:: table:: is_homogeneous(node_ type ntype,
node*& first_nonmatch) final noexcept
Checks if a node contains values/elements of only one type.
Parameters | |
---|---|
ntype | A TOML node type. toml:: |
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
node& toml:: table:: at(std:: wstring_view key)
Gets a reference to the element at a specific key, throwing std::
if none existed.
const node& toml:: table:: at(std:: wstring_view key) const
Gets a reference to the element at a specific key, throwing std::
if none existed.
node* toml:: table:: get(std:: string_view key) noexcept
Gets the node at a specific key.
Parameters | |
---|---|
key | The node's key. |
Returns | A pointer to the node at the specified key, or nullptr. |
auto tbl = toml::table{ { "a", 42, }, { "b", "is the meaning of life, apparently." } }; std::cout << R"(node ["a"] exists: )"sv << !!arr.get("a") << "\n"; std::cout << R"(node ["b"] exists: )"sv << !!arr.get("b") << "\n"; std::cout << R"(node ["c"] exists: )"sv << !!arr.get("c") << "\n"; if (auto val = arr.get("a")) std::cout << R"(node ["a"] was an )"sv << val->type() << "\n";
node ["a"] exists: true node ["b"] exists: true node ["c"] exists: false node ["a"] was an integer
const node* toml:: table:: get(std:: string_view key) const noexcept
Gets the node at a specific key (const overload).
Parameters | |
---|---|
key | The node's key. |
Returns | A pointer to the node at the specified key, or nullptr. |
node* toml:: table:: get(std:: wstring_view key)
Gets the node at a specific key.
Parameters | |
---|---|
key | The node's key. |
Returns | A pointer to the node at the specified key, or nullptr. |
const node* toml:: table:: get(std:: wstring_view key) const
Gets the node at a specific key (const overload).
Parameters | |
---|---|
key | The node's key. |
Returns | A pointer to the node at the specified key, or nullptr. |
template <typename T>
impl::wrap_node<T>* toml:: table:: get_as(std:: string_view key) noexcept
Gets the node at a specific key if it is a particular type.
Template parameters | |
---|---|
T | One of the TOML node or value types. |
Parameters | |
key | The node's key. |
Returns | A pointer to the node at the specified key if it was of the given type, or nullptr. |
auto tbl = toml::table{ { "a", 42, }, { "b", "is the meaning of life, apparently." } }; if (auto val = arr.get_as<int64_t>("a")) std::cout << R"(node ["a"] was an integer with value )"sv << **val << "\n";
node ["a"] was an integer with value 42
template <typename T>
const impl::wrap_node<T>* toml:: table:: get_as(std:: string_view key) const noexcept
Gets the node at a specific key if it is a particular type (const overload).
Template parameters | |
---|---|
T | One of the TOML node or value types. |
Parameters | |
key | The node's key. |
Returns | A pointer to the node at the specified key if it was of the given type, or nullptr. |
template <typename T>
impl::wrap_node<T>* toml:: table:: get_as(std:: wstring_view key)
Gets the node at a specific key if it is a particular type.
Template parameters | |
---|---|
T | One of the TOML node or value types. |
Parameters | |
key | The node's key. |
Returns | A pointer to the node at the specified key if it was of the given type, or nullptr. |
template <typename T>
const impl::wrap_node<T>* toml:: table:: get_as(std:: wstring_view key) const
Gets the node at a specific key if it is a particular type (const overload).
Template parameters | |
---|---|
T | One of the TOML node or value types. |
Parameters | |
key | The node's key. |
Returns | A pointer to the node at the specified key if it was of the given type, or nullptr. |
std:: ostream& operator<<(std:: ostream& lhs,
const table& rhs)
Prints the table out to a stream as formatted TOML.