1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-09 11:01:47 +03:00

fixed [] operator; added README

This commit is contained in:
Niels
2015-02-18 22:28:56 +01:00
parent ca981270a0
commit afd02eee44
4 changed files with 621 additions and 2 deletions

View File

@ -760,6 +760,15 @@ class basic_json
/// access specified element
inline reference operator[](const typename object_t::key_type& key)
{
// implicitly convert null to object
if (m_type == value_t::null)
{
m_type = value_t::object;
Allocator<object_t> alloc;
m_value.object = alloc.allocate(1);
alloc.construct(m_value.object);
}
// at only works for objects
if (m_type != value_t::object)
{
@ -785,6 +794,15 @@ class basic_json
template<typename T, size_t n>
inline reference operator[](const T (&key)[n])
{
// implicitly convert null to object
if (m_type == value_t::null)
{
m_type = value_t::object;
Allocator<object_t> alloc;
m_value.object = alloc.allocate(1);
alloc.construct(m_value.object);
}
// at only works for objects
if (m_type != value_t::object)
{