array
A dynamically sized array of JSON values.
Synopsis
Defined in header <boost/json/array.hpp>.
class array;
Types
Name | Description |
---|---|
Associated Allocator |
|
A random access const iterator to an element. |
|
A const pointer to an element. |
|
A const reference to an element. |
|
A reverse random access const iterator to an element. |
|
The type used to represent signed integers. |
|
A random access iterator to an element. |
|
A pointer to an element. |
|
A reference to an element. |
|
A reverse random access iterator to an element. |
|
The type used to represent unsigned integers. |
|
The type of each element. |
Member Functions
Name | Description |
---|---|
|
Constructors. |
Access an element, with bounds checking. |
|
Access the last element. |
|
Return an iterator to the first element. |
|
Return the number of elements that can be held in currently allocated memory. |
|
Return a const iterator to the first element. |
|
Return a const iterator past the last element. |
|
Clear the contents. |
|
Return a const reverse iterator to the first element of the reversed container. |
|
Return a const reverse iterator to the element following the last element of the reversed container. |
|
Access the underlying array directly. |
|
Insert a constructed element in-place. |
|
Append a constructed element in-place. |
|
Check if the array has no elements. |
|
Return a const iterator past the last element. |
|
Remove elements from the array. |
|
Access the first element. |
|
Return the associated allocator. |
|
Return a pointer to an element if it exists. |
|
Insert elements before the specified location. |
|
Assignment operators. |
|
Access an element. |
|
Remove the last element. |
|
Add an element to the end. |
|
Return a reverse iterator to the first element of the reversed container. |
|
Return a reverse iterator to the element following the last element of the reversed container. |
|
Increase the capacity to at least a certain amount. |
|
Change the number of elements stored. |
|
Request the removal of unused capacity. |
|
Return the number of elements in the array. |
|
Return the associated memory resource. |
|
Swap the contents. |
|
Access an element, with bounds checking. |
|
|
Destructor. |
Static Member Functions
Name | Description |
---|---|
Return the maximum number of elements any array can hold. |
Friends
Name | Description |
---|---|
Return |
|
Serialize |
|
Return |
|
Exchange the given values. |
Description
This is the type used to represent a JSON array as a modifiable container. The interface and performance characteristics are modeled after std::vector<value>
.
Elements are stored contiguously, which means that they can be accessed not only through iterators, but also using offsets to regular pointers to elements. A pointer to an element of an array
may be passed to any function that expects a pointer to value
.
The storage of the array is handled automatically, being expanded and contracted as needed. Arrays usually occupy more space than array language constructs, because more memory is allocated to handle future growth. This way an array does not need to reallocate each time an element is inserted, but only when the additional memory is used up. The total amount of allocated memory can be queried using the capacity
function. Extra memory can be relinquished by calling shrink_to_fit
.
Reallocations are usually costly operations in terms of performance. The reserve
function can be used to eliminate reallocations if the number of elements is known beforehand.
The complexity (efficiency) of common operations on arrays is as follows:
-
Random access—constant O(1).
-
Insertion or removal of elements at the end - amortized constant O(1).
-
Insertion or removal of elements—linear in the distance to the end of the array O(n).
Allocators
All elements stored in the container, and their children if any, will use the same memory resource that was used to construct the container.
Thread Safety
Non-const member functions may not be called concurrently with any other member functions.
Satisfies
Convenience header <boost/json.hpp>.