diff --git a/include/json/value.h b/include/json/value.h index 81598a6..9a302c1 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -585,20 +585,20 @@ public: iterator begin(); iterator end(); - /// @brief Returns a reference to the first element in the container. - /// Calling front on an empty container is undefined behavior. - Value const& front() const; + /// \brief Returns a reference to the first element in the `Value`. + /// Requires that this value holds an array or json object, with at least one element. + const Value& front() const; - /// @brief Returns a reference to the last element in the container. - /// Calling back on an empty container is undefined behavior. - Value const& back() const; - - /// @brief Returns a reference to the first element in the container. - /// Calling front on an empty container is undefined behavior. + /// \brief Returns a reference to the first element in the `Value`. + /// Requires that this value holds an array or json object, with at least one element. Value& front(); - /// @brief Returns a reference to the last element in the container. - /// Calling back on an empty container is undefined behavior. + /// \brief Returns a reference to the last element in the `Value`. + /// Requires that value holds an array or json object, with at least one element. + const Value& back() const; + + /// \brief Returns a reference to the last element in the `Value`. + /// Requires that this value holds an array or json object, with at least one element. Value& back(); // Accessors for the [start, limit) range of bytes within the JSON text from @@ -941,6 +941,14 @@ public: inline void swap(Value& a, Value& b) { a.swap(b); } +inline const Value& Value::front() const { return *begin(); } + +inline Value& Value::front() { return *begin(); } + +inline const Value& Value::back() const { return *(--end()); } + +inline Value& Value::back() { return *(--end()); } + } // namespace Json #pragma pack(pop) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index a41096c..aa2b744 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1495,14 +1495,6 @@ Value::iterator Value::end() { return iterator(); } -Value const& Value::front() const { return *begin(); } - -Value& Value::front() { return *begin(); } - -Value const& Value::back() const { return *(--end()); } - -Value& Value::back() { return *(--end()); } - // class PathArgument // //////////////////////////////////////////////////////////////////