TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ operator[]() [6/8]

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>>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator[] ( size_type  idx) const
inline

access specified array element

Returns a const reference to the element at specified location idx.

Parameters
[in]idxindex of the element to access
Returns
const reference to the element at index idx
Exceptions
type_error.305if the JSON value is not an array; in that case, using the [] operator with an index makes no sense.

@complexity Constant.

@liveexample{The example below shows how array elements can be read using the [] operator.,operatorarray__size_type_const}

Since
version 1.0.0

Definition at line 21437 of file json.hpp.

21438 {
21439 // const operator[] only works for arrays
21440 if (JSON_HEDLEY_LIKELY(is_array()))
21441 {
21442 return m_value.array->operator[](idx);
21443 }
21444
21445 JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name()), *this));
21446 }
json_value m_value
the value of the current element
Definition: json.hpp:24928
constexpr bool is_array() const noexcept
return whether value is an array
Definition: json.hpp:20432
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string
Definition: json.hpp:24883