Return a reference to the element at the specified index.

Synopsis

Declared in <bslstl_sharedptr.h>

add_lvalue_reference<element_type>::type
operator[](ptrdiff_t index) const;

Description

Return a reference providing modifiable access to the object at the specified index offset in the object referred to by this shared pointer. The behavior is undefined unless this shared pointer is not empty, ELEMENT_TYPE is not void (a compiler error will be generated if this operator is instantiated within the shared_ptr<void> class), and this shared pointer refers to an array of ELEMENT_TYPE objects. Instead of element_type &, we use add_lvalue_reference<element_type>::type for the return type because that allows people to instantiate shared_ptr<cv_void>, as long as they don't use this method. Note that this method is logically equivalent to *(get() + index).

Return Value

reference providing modifiable access to the element at index

Parameters

Name

Description

index

zero‐based index into the referenced array

Created with MrDocs