feat: add operator[] to access table/array

This commit is contained in:
ToruNiina
2019-12-10 00:00:05 +09:00
parent 331de4ea5d
commit 8fbeaabfd9

View File

@@ -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());