NeBuild dev
|
A TOML table. More...
#include <table.hpp>
Public Member Functions | |
TOML_NODISCARD_CTOR TOML_EXPORTED_MEMBER_FUNCTION | table () noexcept |
Default constructor. | |
TOML_EXPORTED_MEMBER_FUNCTION | ~table () noexcept |
TOML_NODISCARD_CTOR TOML_EXPORTED_MEMBER_FUNCTION | table (const table &) |
Copy constructor. | |
TOML_NODISCARD_CTOR TOML_EXPORTED_MEMBER_FUNCTION | table (table &&other) noexcept |
Move constructor. | |
TOML_NODISCARD_CTOR TOML_EXPORTED_MEMBER_FUNCTION | table (std::initializer_list< impl::table_init_pair > kvps) |
Constructs a table with one or more initial key-value pairs. | |
TOML_EXPORTED_MEMBER_FUNCTION table & | operator= (const table &) |
Copy-assignment operator. | |
TOML_EXPORTED_MEMBER_FUNCTION table & | operator= (table &&rhs) noexcept |
Move-assignment operator. | |
Type checks | |
TOML_CONST_INLINE_GETTER node_type | type () const noexcept final |
Returns #toml::node_type::table. | |
TOML_PURE_GETTER TOML_EXPORTED_MEMBER_FUNCTION bool | is_homogeneous (node_type ntype) const noexcept final |
TOML_PURE_GETTER TOML_EXPORTED_MEMBER_FUNCTION bool | is_homogeneous (node_type ntype, node *&first_nonmatch) noexcept final |
TOML_PURE_GETTER TOML_EXPORTED_MEMBER_FUNCTION bool | is_homogeneous (node_type ntype, const node *&first_nonmatch) const noexcept final |
TOML_CONST_INLINE_GETTER bool | is_table () const noexcept final |
Returns true . | |
TOML_CONST_INLINE_GETTER bool | is_array () const noexcept final |
Returns false . | |
TOML_PURE_GETTER bool | is_array_of_tables () const noexcept final |
Returns false . | |
TOML_CONST_INLINE_GETTER bool | is_value () const noexcept final |
Returns false . | |
TOML_CONST_INLINE_GETTER bool | is_string () const noexcept final |
Returns false . | |
TOML_CONST_INLINE_GETTER bool | is_integer () const noexcept final |
Returns false . | |
TOML_CONST_INLINE_GETTER bool | is_floating_point () const noexcept final |
Returns false . | |
TOML_CONST_INLINE_GETTER bool | is_number () const noexcept final |
Returns false . | |
TOML_CONST_INLINE_GETTER bool | is_boolean () const noexcept final |
Returns false . | |
TOML_CONST_INLINE_GETTER bool | is_date () const noexcept final |
Returns false . | |
TOML_CONST_INLINE_GETTER bool | is_time () const noexcept final |
Returns false . | |
TOML_CONST_INLINE_GETTER bool | is_date_time () const noexcept final |
Returns false . | |
Type casts | |
TOML_CONST_INLINE_GETTER table * | as_table () noexcept final |
Returns a pointer to the table. | |
TOML_CONST_INLINE_GETTER array * | as_array () noexcept final |
Returns nullptr . | |
TOML_CONST_INLINE_GETTER toml::value< std::string > * | as_string () noexcept final |
Returns nullptr . | |
TOML_CONST_INLINE_GETTER toml::value< int64_t > * | as_integer () noexcept final |
Returns nullptr . | |
TOML_CONST_INLINE_GETTER toml::value< double > * | as_floating_point () noexcept final |
Returns nullptr . | |
TOML_CONST_INLINE_GETTER toml::value< bool > * | as_boolean () noexcept final |
Returns nullptr . | |
TOML_CONST_INLINE_GETTER toml::value< date > * | as_date () noexcept final |
Returns nullptr . | |
TOML_CONST_INLINE_GETTER toml::value< time > * | as_time () noexcept final |
Returns nullptr . | |
TOML_CONST_INLINE_GETTER toml::value< date_time > * | as_date_time () noexcept final |
Returns nullptr . | |
TOML_CONST_INLINE_GETTER const table * | as_table () const noexcept final |
Returns a const-qualified pointer to the table. | |
TOML_CONST_INLINE_GETTER const array * | as_array () const noexcept final |
Returns nullptr . | |
TOML_CONST_INLINE_GETTER const toml::value< std::string > * | as_string () const noexcept final |
Returns nullptr . | |
TOML_CONST_INLINE_GETTER const toml::value< int64_t > * | as_integer () const noexcept final |
Returns nullptr . | |
TOML_CONST_INLINE_GETTER const toml::value< double > * | as_floating_point () const noexcept final |
Returns nullptr . | |
TOML_CONST_INLINE_GETTER const toml::value< bool > * | as_boolean () const noexcept final |
Returns nullptr . | |
TOML_CONST_INLINE_GETTER const toml::value< date > * | as_date () const noexcept final |
Returns nullptr . | |
TOML_CONST_INLINE_GETTER const toml::value< time > * | as_time () const noexcept final |
Returns nullptr . | |
TOML_CONST_INLINE_GETTER const toml::value< date_time > * | as_date_time () const noexcept final |
Returns nullptr . | |
Metadata | |
TOML_PURE_INLINE_GETTER bool | is_inline () const 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. | |
Value retrieval | |
TOML_PURE_GETTER TOML_EXPORTED_MEMBER_FUNCTION node * | get (std::string_view key) noexcept |
Gets the node at a specific key. | |
TOML_PURE_INLINE_GETTER const node * | get (std::string_view key) const noexcept |
Gets the node at a specific key (const overload). | |
TOML_NODISCARD node * | get (std::wstring_view key) |
Gets the node at a specific key. | |
TOML_NODISCARD const node * | get (std::wstring_view key) const |
Gets the node at a specific key (const overload). | |
template<typename T > | |
TOML_PURE_GETTER impl::wrap_node< T > * | get_as (std::string_view key) noexcept |
Gets the node at a specific key if it is a particular type. | |
template<typename T > | |
TOML_PURE_GETTER const impl::wrap_node< T > * | get_as (std::string_view key) const noexcept |
Gets the node at a specific key if it is a particular type (const overload). | |
template<typename T > | |
TOML_NODISCARD impl::wrap_node< T > * | get_as (std::wstring_view key) |
Gets the node at a specific key if it is a particular type. | |
template<typename T > | |
TOML_NODISCARD const impl::wrap_node< T > * | get_as (std::wstring_view key) const |
Gets the node at a specific key if it is a particular type (const overload). | |
TOML_NODISCARD TOML_EXPORTED_MEMBER_FUNCTION node & | at (std::string_view key) |
Gets a reference to the element at a specific key, throwing std::out_of_range if none existed. | |
TOML_NODISCARD const node & | at (std::string_view key) const |
Gets a reference to the element at a specific key, throwing std::out_of_range if none existed. | |
TOML_NODISCARD node & | at (std::wstring_view key) |
Gets a reference to the element at a specific key, throwing std::out_of_range if none existed. | |
TOML_NODISCARD const node & | at (std::wstring_view key) const |
Gets a reference to the element at a specific key, throwing std::out_of_range if none existed. | |
Size and Capacity | |
TOML_PURE_INLINE_GETTER bool | empty () const noexcept |
Returns true if the table is empty. | |
TOML_PURE_INLINE_GETTER size_t | size () const noexcept |
Returns the number of key-value pairs in the table. | |
Searching | |
TOML_PURE_GETTER iterator | 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. | |
TOML_PURE_GETTER const_iterator | 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. | |
TOML_NODISCARD iterator | 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. | |
TOML_NODISCARD const_iterator | 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. | |
TOML_PURE_GETTER TOML_EXPORTED_MEMBER_FUNCTION iterator | find (std::string_view key) noexcept |
Gets an iterator to the node at a specific key. | |
TOML_PURE_GETTER TOML_EXPORTED_MEMBER_FUNCTION const_iterator | find (std::string_view key) const noexcept |
Gets an iterator to the node at a specific key (const overload) | |
TOML_PURE_GETTER bool | contains (std::string_view key) const noexcept |
Returns true if the table contains a node at the given key. | |
TOML_NODISCARD iterator | find (std::wstring_view key) |
Gets an iterator to the node at a specific key. | |
TOML_NODISCARD const_iterator | find (std::wstring_view key) const |
Gets an iterator to the node at a specific key (const overload). | |
TOML_NODISCARD bool | contains (std::wstring_view key) const |
Returns true if the table contains a node at the given key. | |
Erasure | |
iterator | erase (iterator pos) noexcept |
Removes the specified key-value pair from the table. | |
iterator | erase (const_iterator pos) noexcept |
Removes the specified key-value pair from the table (const iterator overload). | |
iterator | erase (const_iterator begin, const_iterator end) noexcept |
Removes the key-value pairs in the range [first, last) from the table. | |
TOML_EXPORTED_MEMBER_FUNCTION size_t | erase (std::string_view key) noexcept |
Removes the value with the given key from the table. | |
size_t | erase (std::wstring_view key) |
Removes the value with the given key from the table. | |
TOML_EXPORTED_MEMBER_FUNCTION table & | prune (bool recursive=true) &noexcept |
Removes empty child arrays and tables. | |
table && | prune (bool recursive=true) &&noexcept |
Removes empty child arrays and tables (rvalue overload). | |
TOML_EXPORTED_MEMBER_FUNCTION void | clear () noexcept |
Removes all key-value pairs from the table. | |
Node views | |
TOML_NODISCARD node_view< node > | operator[] (std::string_view key) noexcept |
Gets a node_view for the selected value. | |
TOML_NODISCARD node_view< const node > | operator[] (std::string_view key) const noexcept |
Gets a node_view for the selected value (const overload). | |
TOML_NODISCARD node_view< node > | operator[] (std::wstring_view key) |
Gets a node_view for the selected value. | |
TOML_NODISCARD node_view< const node > | operator[] (std::wstring_view key) const |
Gets a node_view for the selected value (const overload). | |
Friends | |
std::ostream & | operator<< (std::ostream &lhs, const table &rhs) |
Prints the table out to a stream as formatted TOML. | |
Equality | |
TOML_NODISCARD friend bool | operator== (const table &lhs, const table &rhs) noexcept |
Equality operator. | |
TOML_NODISCARD friend bool | operator!= (const table &lhs, const table &rhs) noexcept |
Inequality operator. | |
Iteration | |
using | iterator = toml::table_iterator |
A BidirectionalIterator for iterating over key-value pairs in a toml::table. | |
using | const_iterator = toml::const_table_iterator |
A BidirectionalIterator for iterating over const key-value pairs in a toml::table. | |
TOML_PURE_INLINE_GETTER iterator | begin () noexcept |
Returns an iterator to the first key-value pair. | |
TOML_PURE_INLINE_GETTER const_iterator | begin () const noexcept |
Returns an iterator to the first key-value pair. | |
TOML_PURE_INLINE_GETTER const_iterator | cbegin () const noexcept |
Returns an iterator to the first key-value pair. | |
TOML_PURE_INLINE_GETTER iterator | end () noexcept |
Returns an iterator to one-past-the-last key-value pair. | |
TOML_PURE_INLINE_GETTER const_iterator | end () const noexcept |
Returns an iterator to one-past-the-last key-value pair. | |
TOML_PURE_INLINE_GETTER const_iterator | cend () const noexcept |
Returns an iterator to one-past-the-last key-value pair. | |
template<typename Func > | |
table & | for_each (Func &&visitor) &noexcept(for_each_is_nothrow< Func &&, table & >::value) |
Invokes a visitor on each key-value pair in the table. | |
template<typename Func > | |
table && | for_each (Func &&visitor) &&noexcept(for_each_is_nothrow< Func &&, table && >::value) |
Invokes a visitor on each key-value pair in the table (rvalue overload). | |
template<typename Func > | |
const table & | for_each (Func &&visitor) const &noexcept(for_each_is_nothrow< Func &&, const table & >::value) |
Invokes a visitor on each key-value pair in the table (const lvalue overload). | |
template<typename Func > | |
const table && | for_each (Func &&visitor) const &&noexcept(for_each_is_nothrow< Func &&, const table && >::value) |
Invokes a visitor on each key-value pair in the table (const rvalue overload). | |
Insertion and Emplacement | |
using | raw_value_type = impl::remove_cvref< ValueType > |
using | value_type = std::conditional_t< std::is_void_v< raw_value_type >, impl::emplaced_type_of< ValueArgs &&... >, raw_value_type > |
using | unwrapped_type = impl::remove_cvref< impl::unwrap_node< value_type > > |
KeyType && | key |
KeyType ValueArgs && | args |
else | |
map_iterator | ipos = insert_with_hint(hint, toml::key{ static_cast<KeyType&&>(key) }, nullptr) |
return | iterator { ipos } |
TOML_CONSTRAINED_TEMPLATE ((is_key_or_convertible< KeyType && >||impl::is_wide_string< KeyType >), typename ValueType=void, typename KeyType, typename... ValueArgs) iterator emplace_hint(const_iterator hint | |
Emplaces a new value at a specific key if one did not already exist. | |
if | constexpr (impl::is_wide_string< KeyType >) |
if (!ipos->second) | |
TOML_CONSTRAINED_TEMPLATE ((is_key_or_convertible< KeyType && >||impl::is_wide_string< KeyType >), typename KeyType, typename ValueType) std | |
Inserts a new value at a specific key if one did not already exist. | |
void | insert (Iter begin, Iter end, value_flags flags=preserve_source_value_flags) |
Inserts a series of key-value pairs into the table. | |
TOML_CONSTRAINED_TEMPLATE ((is_key_or_convertible< KeyType && >||impl::is_wide_string< KeyType >), typename KeyType, typename ValueType) std | |
Inserts or assigns a value at a specific key. | |
TOML_CONSTRAINED_TEMPLATE ((is_key_or_convertible< KeyType && >||impl::is_wide_string< KeyType >), typename ValueType=void, typename KeyType, typename... ValueArgs) std | |
Emplaces a new value at a specific key if one did not already exist. | |
A TOML table.
\detail The interface of this type is modeled after std::map, with some additional considerations made for the heterogeneous nature of a TOML table.
\cpp toml::table tbl = toml::parse(R"( @iverbatim [animals] cats = [ "tiger", "lion", "puma" ] birds = [ "macaw", "pigeon", "canary" ] fish = [ "salmon", "trout", "carp" ] @endiverbatim )"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"; \ecpp
\out cats: ['tiger', 'lion', 'puma'] fish[1] : 'trout' cats : ['tiger', 'lion', 'puma'] fish[1] : 'trout' \eout
using table::const_iterator = toml::const_table_iterator |
A BidirectionalIterator for iterating over const key-value pairs in a toml::table.
using table::iterator = toml::table_iterator |
A BidirectionalIterator for iterating over key-value pairs in a toml::table.
using table::raw_value_type = impl::remove_cvref<ValueType> |
using table::unwrapped_type = impl::remove_cvref<impl::unwrap_node<value_type> > |
using table::value_type = std:: conditional_t<std::is_void_v<raw_value_type>, impl::emplaced_type_of<ValueArgs&&...>, raw_value_type> |
|
noexcept |
Default constructor.
|
noexcept |
TOML_NODISCARD_CTOR TOML_EXPORTED_MEMBER_FUNCTION table::table | ( | const table & | ) |
Copy constructor.
|
noexcept |
Move constructor.
|
inlineexplicit |
Constructs a table with one or more initial key-value pairs.
\detail \cpp auto tbl = toml::table{ { "foo", 1 }, { "bar", 2.0 }, { "kek", "three" } }; std::cout << tbl << "\n"; \ecpp
\out { foo = 1, bar = 2.0, kek = "three" } \eout
kvps | A list of key-value pairs used to initialize the table. |
|
inlinefinalnoexcept |
Returns nullptr
.
|
inlinefinalnoexcept |
Returns nullptr
.
|
inlinefinalnoexcept |
Returns nullptr
.
|
inlinefinalnoexcept |
Returns nullptr
.
|
inlinefinalnoexcept |
Returns nullptr
.
|
inlinefinalnoexcept |
Returns nullptr
.
|
inlinefinalnoexcept |
Returns nullptr
.
|
inlinefinalnoexcept |
Returns nullptr
.
|
inlinefinalnoexcept |
Returns nullptr
.
|
inlinefinalnoexcept |
Returns nullptr
.
|
inlinefinalnoexcept |
Returns nullptr
.
|
inlinefinalnoexcept |
Returns nullptr
.
|
inlinefinalnoexcept |
Returns nullptr
.
|
inlinefinalnoexcept |
Returns nullptr
.
|
inlinefinalnoexcept |
Returns a const-qualified pointer to the table.
|
inlinefinalnoexcept |
Returns a pointer to the table.
|
inlinefinalnoexcept |
Returns nullptr
.
|
inlinefinalnoexcept |
Returns nullptr
.
TOML_NODISCARD TOML_EXPORTED_MEMBER_FUNCTION node & table::at | ( | std::string_view | key | ) |
Gets a reference to the element at a specific key, throwing std::out_of_range
if none existed.
|
inline |
Gets a reference to the element at a specific key, throwing std::out_of_range
if none existed.
|
inline |
Gets a reference to the element at a specific key, throwing std::out_of_range
if none existed.
\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.
|
inline |
Gets a reference to the element at a specific key, throwing std::out_of_range
if none existed.
\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.
|
inlinenoexcept |
Returns an iterator to the first key-value pair.
|
inlinenoexcept |
Returns an iterator to the first key-value pair.
|
inlinenoexcept |
Returns an iterator to the first key-value pair.
|
inlinenoexcept |
Returns an iterator to one-past-the-last key-value pair.
|
noexcept |
Removes all key-value pairs from the table.
|
inlineconstexpr |
|
inlinenoexcept |
Returns true if the table contains a node at the given key.
|
inline |
Returns true if the table contains a node at the given key.
\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.
|
inlinenoexcept |
Returns true if the table is empty.
|
inlinenoexcept |
Returns an iterator to one-past-the-last key-value pair.
|
inlinenoexcept |
Returns an iterator to one-past-the-last key-value pair.
|
inlinenoexcept |
Removes the key-value pairs in the range [first, last) from the table.
\detail \cpp 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"; \ecpp
\out { a = 1, b = "bad", c = "karma", d = 2 } { a = 1, d = 2 } \eout
begin | Iterator to the first key-value pair being erased. |
end | Iterator to the one-past-the-last key-value pair being erased. |
|
inlinenoexcept |
Removes the specified key-value pair from the table (const iterator overload).
\detail \cpp auto tbl = toml::table{ { "a", 1 }, { "b", 2 }, { "c", 3 } }; std::cout << tbl << "\n";
tbl.erase(tbl.cbegin() + 1); std::cout << tbl << "\n"; \ecpp
\out { a = 1, b = 2, c = 3 } { a = 1, c = 3 } \eout
pos | Iterator to the key-value pair being erased. |
Removes the specified key-value pair from the table.
\detail \cpp auto tbl = toml::table{ { "a", 1 }, { "b", 2 }, { "c", 3 } }; std::cout << tbl << "\n";
tbl.erase(tbl.begin() + 1); std::cout << tbl << "\n"; \ecpp
\out { a = 1, b = 2, c = 3 } { a = 1, c = 3 } \eout
pos | Iterator to the key-value pair being erased. |
|
noexcept |
Removes the value with the given key from the table.
\detail \cpp 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"; \ecpp
\out { a = 1, b = 2, c = 3 } true false { a = 1, c = 3 } \eout
key | Key to erase. |
|
inline |
Removes the value with the given key from the table.
\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.
key | Key to erase. |
|
noexcept |
Gets an iterator to the node at a specific key (const overload)
key | The node's key. |
|
noexcept |
Gets an iterator to the node at a specific key.
key | The node's key. |
|
inline |
Gets an iterator to the node at a specific key.
\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.
key | The node's key. |
|
inline |
Gets an iterator to the node at a specific key (const overload).
\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.
key | The node's key. |
|
inlinenoexcept |
Invokes a visitor on each key-value pair in the table (rvalue overload).
|
inlinenoexcept |
Invokes a visitor on each key-value pair in the table.
Func | A callable type invocable with one of the following signatures:
bool (or something convertible to bool ) will cause iteration to stop if they return false . |
visitor | The visitor object. |
\cpp toml::table tbl{ { "0", 0 }, { "1", 1 }, { "2", 2 }, { "3", 3.0 }, { "4", "four" }, { "5", "five" }, { "6", 6 } };
// select only the integers using a strongly-typed visitor tbl.for_each([](toml::value<int64_t>& val) { std::cout << val << ", "; }); std::cout << "\n";
// select all the numeric values using a generic visitor + is_number<> metafunction tbl.for_each([](auto&& val) { if constexpr (toml::is_number<decltype(val)>) std::cout << val << ", "; }); std::cout << "\n";
// select all the numeric values until we encounter something non-numeric tbl.for_each([](auto&& val) { if constexpr (toml::is_number<decltype(val)>) { std::cout << val << ", "; return true; // "keep going" } else return false; // "stop!"
}); std::cout << "\n\n";
// visitors may also recieve the key tbl.for_each([](const toml::key& key, auto&& val) { std::cout << key << ": " << val << "\n"; });
\ecpp \out 0, 1, 2, 6, 0, 1, 2, 3.0, 6, 0, 1, 2, 3.0,
0: 0 1: 1 2: 2 3: 3.0 4: 'four' 5: 'five' 6: 6 \eout
|
inlinenoexcept |
Invokes a visitor on each key-value pair in the table (const rvalue overload).
|
inlinenoexcept |
Invokes a visitor on each key-value pair in the table (const lvalue overload).
|
inlinenoexcept |
Gets the node at a specific key (const overload).
key | The node's key. |
|
noexcept |
Gets the node at a specific key.
\detail \cpp 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"; \ecpp
\out node ["a"] exists: true node ["b"] exists: true node ["c"] exists: false node ["a"] was an integer \eout
key | The node's key. |
|
inline |
Gets the node at a specific key.
\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.
key | The node's key. |
|
inline |
Gets the node at a specific key (const overload).
\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.
key | The node's key. |
|
inlinenoexcept |
Gets the node at a specific key if it is a particular type (const overload).
T | One of the TOML node or value types. |
key | The node's key. |
|
inlinenoexcept |
Gets the node at a specific key if it is a particular type.
\detail \cpp 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"; \ecpp
\out node ["a"] was an integer with value 42 \eout
T | One of the TOML node or value types. |
key | The node's key. |
|
inline |
Gets the node at a specific key if it is a particular type.
\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.
T | One of the TOML node or value types. |
key | The node's key. |
|
inline |
Gets the node at a specific key if it is a particular type (const overload).
\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.
T | One of the TOML node or value types. |
key | The node's key. |
|
inline |
|
inline |
Inserts a series of key-value pairs into the table.
\detail \godbolt{bzYcce}
\cpp 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"; \ecpp
\out a = 1 b = 2 c = 3
a = 1 b = 2 c = 3 d = 42 \eout
Iter | An InputIterator to a collection of key-value pairs. |
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. |
insert(key, value)
for each key-value pair covered by the iterator range, so any values with keys already found in the table will not be replaced.
|
inlinefinalnoexcept |
Returns false
.
|
inlinefinalnoexcept |
Returns false
.
|
inlinefinalnoexcept |
Returns false
.
|
inlinefinalnoexcept |
Returns false
.
|
inlinefinalnoexcept |
Returns false
.
|
inlinefinalnoexcept |
Returns false
.
|
finalnoexcept |
|
finalnoexcept |
|
finalnoexcept |
|
inlinenoexcept |
Returns true if this table is an inline table.
|
inlinenoexcept |
Sets whether this table is a TOML inline table.
\detail \godbolt{an9xdj}
\cpp 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"; \ecpp
\out is inline? false a = 1 b = 2 c = 3
[d] e = 4
is inline? true { a = 1, b = 2, c = 3, d = { e = 4 } } \eout
val | The new value for 'inline'. |
|
inlinefinalnoexcept |
Returns false
.
|
inlinefinalnoexcept |
Returns false
.
|
inlinefinalnoexcept |
Returns false
.
|
inlinefinalnoexcept |
Returns true
.
|
inlinefinalnoexcept |
Returns false
.
|
inlinefinalnoexcept |
Returns false
.
|
inlinenoexcept |
Returns a const iterator to the first key-value pair with key that is not less than the given key.
|
inlinenoexcept |
Returns an iterator to the first key-value pair with key that is not less than the given key.
|
inline |
Returns an iterator to the first key-value pair with key that is not less than the given key.
\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.
|
inline |
Returns a const iterator to the first key-value pair with key that is not less than the given key.
\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.
TOML_EXPORTED_MEMBER_FUNCTION table & table::operator= | ( | const table & | ) |
Copy-assignment operator.
|
noexcept |
Move-assignment operator.
|
inlinenoexcept |
Gets a node_view for the selected value (const overload).
key | The key used for the lookup. |
|
inlinenoexcept |
Gets a node_view for the selected value.
key | The key used for the lookup. |
|
inline |
Gets a node_view for the selected value.
\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.
key | The key used for the lookup. |
|
inline |
Gets a node_view for the selected value (const overload).
\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.
key | The key used for the lookup. |
|
inlinenoexcept |
Removes empty child arrays and tables (rvalue overload).
recursive | Should child arrays and tables themselves be pruned? |
|
noexcept |
Removes empty child arrays and tables.
\detail \cpp
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"; \ecpp
\out { a = 1, b = [], c = [ {}, [] ] } { a = 1 } \eout
recursive | Should child arrays and tables themselves be pruned? |
|
inlinenoexcept |
Returns the number of key-value pairs in the table.
|
inline |
Inserts a new value at a specific key if one did not already exist.
\detail \godbolt{bMnW5r}
\cpp 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"; \ecpp
\out a = 1 b = 2 c = 3
inserted with key 'a': false inserted with key 'd': true a = 1 b = 2 c = 3 d = 42 \eout
KeyType | A toml::key or any compatible string type. |
ValueType | toml::node, toml::node_view, toml::table, toml::array, or a native TOML value type (or a type promotable to one). |
key | The key at which to insert the new value. |
val | The new value to insert. |
flags | Value flags to apply to new values. |
{ end(), false }
{ end(), false }
if the input value was an null toml::node_view, because no insertion can take place. This is the only circumstance in which this can occur.
|
inline |
Inserts or assigns a value at a specific key.
\detail \godbolt{ddK563}
\cpp 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"; \ecpp
\out 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 \eout
KeyType | A toml::key or any compatible string type. |
ValueType | toml::node, toml::node_view, toml::table, toml::array, or a native TOML value type (or a type promotable to one). |
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. |
true
if the value was inserted, false
if it was assigned. { end(), false }
{ end(), false }
if the input value was a null toml::node_view, because no insertion or assignment can take place. This is the only circumstance in which this can occur. table::TOML_CONSTRAINED_TEMPLATE | ( | (is_key_or_convertible< KeyType && >||impl::is_wide_string< KeyType >) | , |
typename ValueType | = void , |
||
typename KeyType | , | ||
typename... | ValueArgs | ||
) |
Emplaces a new value at a specific key if one did not already exist.
ValueType | toml::table, toml::array, or any native TOML value type. |
KeyType | A toml::key or any compatible string type. |
ValueArgs | Value constructor argument types. |
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. |
|
inline |
Emplaces a new value at a specific key if one did not already exist.
\detail \cpp 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"; \ecpp
\out { a = 1, b = 2, c = 3 } emplaced with key 'a': false emplaced with key 'd': true { a = 1, b = 2, c = 3, d = "drill" } \eout
ValueType | toml::table, toml::array, or any native TOML value type. |
KeyType | A toml::key or any compatible string type. |
ValueArgs | Value constructor argument types. |
key | The key at which to emplace the new value. |
args | Arguments to forward to the value's constructor. |
|
inlinefinalnoexcept |
Returns #toml::node_type::table.
|
friend |
Inequality operator.
lhs | The LHS table. |
rhs | The RHS table. |
|
friend |
Prints the table out to a stream as formatted TOML.
\availability This operator is only available when TOML_ENABLE_FORMATTERS is enabled.
|
friend |
Equality operator.
lhs | The LHS table. |
rhs | The RHS table. |
KeyType ValueArgs&& table::args |
table::else |
map_iterator table::ipos = insert_with_hint(hint, toml::key{ static_cast<KeyType&&>(key) }, nullptr) |
return table::iterator { ipos } |
KeyType&& table::key |