From 8fbeaabfd9cb2d64c66f8c1ec79b2837f6575c41 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Tue, 10 Dec 2019 00:00:05 +0900 Subject: [PATCH] feat: add operator[] to access table/array --- toml/value.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/toml/value.hpp b/toml/value.hpp index e2f5cf8..1b492a4 100644 --- a/toml/value.hpp +++ b/toml/value.hpp @@ -1579,6 +1579,14 @@ class basic_value { 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) { @@ -1589,6 +1597,15 @@ class basic_value 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 { return source_location(this->region_info_.get());