Array Flashcards

1
Q

Element access

at( )

A

Access specified element with bounds checking.

Parameters
(none)

Return value
The number of elements in the container.

Complexity
Constant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Element access

operator[]

A

access specified element

Returns a reference to the element at specified location pos. No bounds checking is performed.

Parameters
pos - position of the element to return

Return value
Reference to the requested element.

Complexity
Constant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Element access

front( )

A

access the first element

Returns a reference to the first element in the container.

Calling front on an empty container is undefined.

Parameters
(none)

Return value
reference to the first element

Complexity
Constant

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Element access

back( )

A

access the last element

Returns a reference to the last element in the container.

Calling back on an empty container causes undefined behavior.

Parameters
(none)

Return value
Reference to the last element.

Complexity
Constant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Element access

data( )

A

direct access to the underlying array

Returns pointer to the underlying array serving as element storage. The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty (data() is not dereferenceable in that case).

Parameters
(none)

Return value
Pointer to the underlying element storage. For non-empty containers, the returned pointer compares equal to the address of the first element.

Complexity
Constant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Iterators
begin
cbegin( )

A

returns an iterator to the beginning

returns an iterator to the first element of the array.

If the array is empty, the returned iterator will be equal to end().

range-begin-end.svg

Parameters
(none)

Return value
Iterator to the first element.

Complexity
Constant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Iterators
end
cend( )

A

returns an iterator to the end
Returns an iterator to the element following the last element of the array.

This element acts as a placeholder; attempting to access it results in undefined behavior.

range-begin-end.svg

Parameters
(none)

Return value
Iterator to the element following the last element.

Complexity
Constant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Iterators
rbegin
crbegin( )

A

returns a reverse iterator to the beginning

Returns a reverse iterator to the first element of the reversed array. It corresponds to the last element of the non-reversed array. If the array is empty, the returned iterator is equal to rend().

range-rbegin-rend.svg

Parameters
(none)

Return value
Reverse iterator to the first element.

Complexity
Constant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Iterators
rend
crend( )

A

returns a reverse iterator to the end

Returns a reverse iterator to the element following the last element of the reversed array. It corresponds to the element preceding the first element of the non-reversed array. This element acts as a placeholder, attempting to access it results in undefined behavior.

range-rbegin-rend.svg

Parameters
(none)

Return value
Reverse iterator to the element following the last element.

Complexity
Constant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Capacity

empty( )

A

checks whether the container is empty
Checks if the container has no elements, i.e. whether begin() == end().

Parameters
(none)

Return value
true if the container is empty, false otherwise

Complexity
Constant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Capacity

size( )

A

returns the number of elements
Returns the number of elements in the container, i.e. std::distance(begin(), end()).

Parameters
(none)

Return value
The number of elements in the container.

Complexity
Constant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Capacity

max_size( )

A

returns the maximum possible number of elements
Returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. std::distance(begin(), end()) for the largest container.

Parameters
(none)

Return value
Maximum number of elements.

Complexity
Constant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Operations

fill( )

A

fill the container with specified value
Assigns the given value value to all elements in the container.

Parameters
value - the value to assign to the elements
Return value
(none)

Complexity
Linear in the size of the container.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Operations

swap( )

A

swaps the contents
Exchanges the contents of the container with those of other. Does not cause iterators and references to associate with the other container.

Parameters
other - container to exchange the contents with
Return value
(none)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly