template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::empty |
( |
| ) |
const |
|
inlinenoexcept |
checks whether the container is empty.
Checks if a JSON value has no elements (i.e. whether its size is 0
).
- Returns
- The return value depends on the different types and is defined as follows:
Value type | return value |
null | true |
boolean | false |
string | false |
number | false |
binary | false |
object | result of function object_t::empty() |
array | result of function array_t::empty() |
@liveexample{The following code uses empty()
to check if a JSON object contains any elements.,empty}
@complexity Constant, as long as array_t and object_t satisfy the Container concept; that is, their empty()
functions have constant complexity.
@iterators No changes.
@exceptionsafety No-throw guarantee: this function never throws exceptions.
- Note
- This function does not return whether a string stored as JSON value is empty - it returns whether the JSON container itself is empty which is false in the case of a string.
@requirement This function helps basic_json
satisfying the Container requirements:
- The complexity is constant.
- Has the semantics of
begin() == end()
.
- See also
- see size() – returns the number of elements
- Since
- version 1.0.0
Definition at line 22832 of file json.hpp.
22833 {
22834 switch (m_type)
22835 {
22837 {
22838
22839 return true;
22840 }
22841
22843 {
22844
22845 return m_value.array->empty();
22846 }
22847
22849 {
22850
22851 return m_value.object->empty();
22852 }
22853
22861 default:
22862 {
22863
22864 return false;
22865 }
22866 }
22867 }
json_value m_value
the value of the current element
@ number_integer
number value (signed integer)
@ discarded
discarded by the parser callback function
@ binary
binary array (ordered collection of bytes)
@ object
object (unordered set of name/value pairs)
@ number_float
number value (floating-point)
@ number_unsigned
number value (unsigned integer)
@ array
array (ordered collection of values)