fixed [] operator; added README
This commit is contained in:
parent
ca981270a0
commit
afd02eee44
4 changed files with 621 additions and 2 deletions
18
src/json.hpp
18
src/json.hpp
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue