mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 10:28:09 +08:00
feat: add operator[] to access table/array
This commit is contained in:
@@ -1579,6 +1579,14 @@ class basic_value
|
|||||||
{
|
{
|
||||||
return this->as_table().at(k);
|
return this->as_table().at(k);
|
||||||
}
|
}
|
||||||
|
value_type& operator[](const key& k)
|
||||||
|
{
|
||||||
|
if(this->is_uninitialized())
|
||||||
|
{
|
||||||
|
*this = table_type{};
|
||||||
|
}
|
||||||
|
return this->as_table()[k];
|
||||||
|
}
|
||||||
|
|
||||||
value_type& at(const std::size_t idx)
|
value_type& at(const std::size_t idx)
|
||||||
{
|
{
|
||||||
@@ -1589,6 +1597,15 @@ class basic_value
|
|||||||
return this->as_array().at(idx);
|
return this->as_array().at(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value_type& operator[](const std::size_t idx) noexcept
|
||||||
|
{
|
||||||
|
return this->as_array(std::nothrow)[idx];
|
||||||
|
}
|
||||||
|
value_type const& operator[](const std::size_t idx) const noexcept
|
||||||
|
{
|
||||||
|
return this->as_array(std::nothrow)[idx];
|
||||||
|
}
|
||||||
|
|
||||||
source_location location() const
|
source_location location() const
|
||||||
{
|
{
|
||||||
return source_location(this->region_info_.get());
|
return source_location(this->region_info_.get());
|
||||||
|
Reference in New Issue
Block a user