Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the develop branch, built from commit 541b305a06.
PrevUpHomeNext

array

A dynamically sized array of JSON values.

Synopsis

Defined in header <boost/json/array.hpp>

class array
Types

Name

Description

allocator_type

Associated Allocator

const_iterator

A random access const iterator to an element.

const_pointer

A const pointer to an element.

const_reference

A const reference to an element.

const_reverse_iterator

A reverse random access const iterator to an element.

difference_type

The type used to represent signed integers.

iterator

A random access iterator to an element.

pointer

A pointer to an element.

reference

A reference to an element.

reverse_iterator

A reverse random access iterator to an element.

size_type

The type used to represent unsigned integers.

value_type

The type of each element.

Member Functions

Name

Description

array [constructor]

Constructor.

Copy constructor.

Pilfer constructor.

Move constructor.

at

Access an element, with bounds checking.

back

Access the last element.

begin

Return an iterator to the first element.

Return a const iterator to the first element.

capacity

Return the number of elements that can be held in currently allocated memory.

cbegin

Return a const iterator to the first element.

cend

Return a const iterator to the element following the last element.

clear

Clear the contents.

crbegin

Return a const reverse iterator to the first element of the reversed container.

crend

Return a const reverse iterator to the element following the last element of the reversed container.

data

Access the underlying array directly.

emplace

Insert a constructed element in-place.

emplace_back

Append a constructed element in-place.

empty

Check if the array has no elements.

end

Return an iterator to the element following the last element.

Return a const iterator to the element following the last element.

erase

Erase elements from the container.

front

Access the first element.

get_allocator

Return the associated allocator.

if_contains

Return a pointer to an element, or nullptr if the index is invalid.

insert

Insert elements before the specified location.

operator=

Copy assignment.

Move assignment.

Assignment.

operator[]

Access an element.

pop_back

Remove the last element.

push_back

Add an element to the end.

rbegin

Return a reverse iterator to the first element of the reversed container.

Return a const reverse iterator to the first element of the reversed container.

rend

Return a reverse iterator to the element following the last element of the reversed container.

Return a const reverse iterator to the element following the last element of the reversed container.

reserve

Increase the capacity to at least a certain amount.

resize

Change the number of elements stored.

shrink_to_fit

Request the removal of unused capacity.

size

Return the number of elements in the array.

storage

Return the associated memory resource.

swap

Swap the contents.

~array [destructor]

Destructor.

Static Member Functions

Name

Description

max_size

Return the maximum number of elements any array can hold.

Friends

Name

Description

operator==

Return true if two arrays are equal.

operator!=

Return true if two arrays are not equal.

operator<<

Serialize array to an output stream.

swap

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:

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

ContiguousContainer, ReversibleContainer, and SequenceContainer.

Convenience header <boost/json.hpp>


PrevUpHomeNext