9#if !TOML_IMPLEMENTATION
10#error This is an implementation-only header.
21#if TOML_LIFETIME_HOOKS
28#if TOML_LIFETIME_HOOKS
34 table::table(
const impl::table_init_pair*
b,
const impl::table_init_pair*
e) {
35#if TOML_LIFETIME_HOOKS
49 map_.insert_or_assign(std::move(
b->key), std::move(
b->value));
55 : node(other), inline_{other.inline_} {
56 for (
auto&& [
k,
v] : other.map_) map_.emplace_hint(map_.end(),
k, impl::make_node(*
v));
58#if TOML_LIFETIME_HOOKS
65 : node(std::move(other)), map_{std::move(other.map_)}, inline_{other.inline_} {
66#if TOML_LIFETIME_HOOKS
76 for (
auto&& [
k,
v] :
rhs.map_)
map_.emplace_hint(
map_.end(),
k, impl::make_node(*
v));
85 node::operator=(std::move(
rhs));
86 map_ = std::move(
rhs.map_);
87 inline_ =
rhs.inline_;
95 if (map_.empty())
return false;
97 if (ntype == node_type::none) ntype = map_.cbegin()->second->type();
99 for (
auto&& [
k,
v] : map_) {
101 if (
v->type() != ntype)
return false;
114 if (ntype == node_type::none) ntype = map_.cbegin()->second->type();
115 for (
const auto& [
k,
v] : map_) {
117 if (
v->type() != ntype) {
118 first_nonmatch =
v.get();
130 first_nonmatch = fnm;
136 node*
table::get(std::string_view key)
noexcept {
137 if (
auto it = map_.find(key); it != map_.end())
return it->second.get();
145#if TOML_COMPILER_HAS_EXCEPTIONS
150 err.append(
"' not found in table"sv);
151 throw std::out_of_range{err};
166 return map_.lower_bound(key);
172 return iterator{map_.find(key)};
178 return const_iterator{map_.find(key)};
183 return map_.erase(
pos);
188 return map_.erase(begin,
end);
193 if (
auto it = map_.find(key); it != map_.end()) {
202 if (map_.empty())
return *
this;
204 for (
auto it = map_.begin(); it != map_.end();) {
205 if (
auto arr = it->second->as_array()) {
206 if (recursive) arr->
prune(
true);
212 }
else if (
auto tbl = it->second->as_table()) {
213 if (recursive) tbl->prune(
true);
239 if (&
lhs == &
rhs)
return true;
240 if (
lhs.map_.size() !=
rhs.map_.size())
return false;
242 for (
auto l =
lhs.map_.begin(),
r =
rhs.map_.begin(),
e =
lhs.map_.end(); l !=
e; l++,
r++) {
243 if (l->first !=
r->first)
return false;
245 const auto lhs_type = l->second->type();
246 const node& rhs_ = *
r->second;
247 const auto rhs_type = rhs_.type();
248 if (lhs_type != rhs_type)
return false;
250 const bool equal = l->second->visit([&](
const auto& lhs_)
noexcept {
251 return lhs_ == *
reinterpret_cast<std::remove_reference_t<decltype(lhs_)
>*>(&rhs_);
253 if (!
equal)
return false;
bool equal(const T &x, const U &y)
TOML_EXPORTED_MEMBER_FUNCTION table & prune(bool recursive=true) &noexcept
Removes empty child arrays and tables.
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_CTOR TOML_EXPORTED_MEMBER_FUNCTION table() noexcept
Default constructor.
TOML_PURE_GETTER TOML_EXPORTED_MEMBER_FUNCTION node * get(std::string_view key) noexcept
Gets the node at a specific key.
toml::const_table_iterator const_iterator
A BidirectionalIterator for iterating over const key-value pairs in a toml::table.
TOML_EXPORTED_MEMBER_FUNCTION void clear() noexcept
Removes all key-value pairs from the table.
toml::table_iterator iterator
A BidirectionalIterator for iterating over key-value pairs in a toml::table.
TOML_PURE_GETTER TOML_EXPORTED_MEMBER_FUNCTION bool is_homogeneous(node_type ntype) const noexcept final
TOML_EXPORTED_MEMBER_FUNCTION table & operator=(const table &)
Copy-assignment operator.
TOML_EXPORTED_MEMBER_FUNCTION ~table() noexcept
TOML_PURE_GETTER TOML_EXPORTED_MEMBER_FUNCTION iterator find(std::string_view key) noexcept
Gets an iterator to the node at a specific key.
iterator erase(iterator pos) noexcept
Removes the specified key-value pair from the table.
#define TOML_CALLCONV
Calling convention to apply to exported free/static functions. \detail Not defined by default (let th...
#define TOML_ASSERT_ASSUME(expr)
#define TOML_UNLIKELY(...)
#define TOML_EXTERNAL_LINKAGE
#define TOML_NAMESPACE_END