Commit b80ca376 authored by Niels's avatar Niels

added some missing features from 2.0 version

parent 2d8b3628
...@@ -725,6 +725,18 @@ class basic_json ...@@ -725,6 +725,18 @@ class basic_json
return m_value.object->operator[](key); return m_value.object->operator[](key);
} }
/// access specified element
inline const_reference operator[](const typename object_t::key_type& key) const
{
// at only works for objects
if (m_type != value_t::object)
{
throw std::runtime_error("cannot use [] with " + type_name());
}
return m_value.object->operator[](key);
}
/// access specified element (needed for clang) /// access specified element (needed for clang)
template<typename T, size_t n> template<typename T, size_t n>
inline reference operator[](const T (&key)[n]) inline reference operator[](const T (&key)[n])
...@@ -738,6 +750,19 @@ class basic_json ...@@ -738,6 +750,19 @@ class basic_json
return m_value.object->operator[](key); return m_value.object->operator[](key);
} }
/// access specified element (needed for clang)
template<typename T, size_t n>
inline const_reference operator[](const T (&key)[n]) const
{
// at only works for objects
if (m_type != value_t::object)
{
throw std::runtime_error("cannot use [] with " + type_name());
}
return m_value.object->operator[](key);
}
/// find an element in an object /// find an element in an object
inline iterator find(typename object_t::key_type key) inline iterator find(typename object_t::key_type key)
...@@ -1686,6 +1711,9 @@ class basic_json ...@@ -1686,6 +1711,9 @@ class basic_json
/// the category of the iterator /// the category of the iterator
using iterator_category = std::bidirectional_iterator_tag; using iterator_category = std::bidirectional_iterator_tag;
/// default constructor
inline iterator() = default;
/// constructor for a given JSON instance /// constructor for a given JSON instance
inline iterator(pointer object) : m_object(object) inline iterator(pointer object) : m_object(object)
{ {
...@@ -2044,6 +2072,9 @@ class basic_json ...@@ -2044,6 +2072,9 @@ class basic_json
/// the category of the iterator /// the category of the iterator
using iterator_category = std::bidirectional_iterator_tag; using iterator_category = std::bidirectional_iterator_tag;
/// default constructor
inline const_iterator() = default;
/// constructor for a given JSON instance /// constructor for a given JSON instance
inline const_iterator(pointer object) : m_object(object) inline const_iterator(pointer object) : m_object(object)
{ {
......
...@@ -725,6 +725,18 @@ class basic_json ...@@ -725,6 +725,18 @@ class basic_json
return m_value.object->operator[](key); return m_value.object->operator[](key);
} }
/// access specified element
inline const_reference operator[](const typename object_t::key_type& key) const
{
// at only works for objects
if (m_type != value_t::object)
{
throw std::runtime_error("cannot use [] with " + type_name());
}
return m_value.object->operator[](key);
}
/// access specified element (needed for clang) /// access specified element (needed for clang)
template<typename T, size_t n> template<typename T, size_t n>
inline reference operator[](const T (&key)[n]) inline reference operator[](const T (&key)[n])
...@@ -738,6 +750,19 @@ class basic_json ...@@ -738,6 +750,19 @@ class basic_json
return m_value.object->operator[](key); return m_value.object->operator[](key);
} }
/// access specified element (needed for clang)
template<typename T, size_t n>
inline const_reference operator[](const T (&key)[n]) const
{
// at only works for objects
if (m_type != value_t::object)
{
throw std::runtime_error("cannot use [] with " + type_name());
}
return m_value.object->operator[](key);
}
/// find an element in an object /// find an element in an object
inline iterator find(typename object_t::key_type key) inline iterator find(typename object_t::key_type key)
...@@ -1686,6 +1711,9 @@ class basic_json ...@@ -1686,6 +1711,9 @@ class basic_json
/// the category of the iterator /// the category of the iterator
using iterator_category = std::bidirectional_iterator_tag; using iterator_category = std::bidirectional_iterator_tag;
/// default constructor
inline iterator() = default;
/// constructor for a given JSON instance /// constructor for a given JSON instance
inline iterator(pointer object) : m_object(object) inline iterator(pointer object) : m_object(object)
{ {
...@@ -2044,6 +2072,9 @@ class basic_json ...@@ -2044,6 +2072,9 @@ class basic_json
/// the category of the iterator /// the category of the iterator
using iterator_category = std::bidirectional_iterator_tag; using iterator_category = std::bidirectional_iterator_tag;
/// default constructor
inline const_iterator() = default;
/// constructor for a given JSON instance /// constructor for a given JSON instance
inline const_iterator(pointer object) : m_object(object) inline const_iterator(pointer object) : m_object(object)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment