My Project
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Related Functions | List of all members
bsl::array< T, N > Class Template Referencefinal

Provides a safe encapsulation for a C-style array, minicing the std::array APIs. This container is an aggregate type, but unlike a std::array, a bsl::array does not provide the T[n] syntax as this is nither Core Guideline compliant or compliant with AUTOSAR. Instead we provide at_if() versions which return a pointer to the element being requested. If the element does not exist, a nullptr is returned, providing a means to check for logic errors without the need for exceptions or failing fast which is not compliant with AUTOSAR. We also do not support N==0 type arrays and like other BSL classes, we do not support the member version of swap() and fill() as they are not compliant with AUTOSAR (due to the name reuse). User bsl::swap() and bsl::fill() instead. More...

#include <array.hpp>

Public Types

using value_type = T
 alias for: T
 
using size_type = bsl::uintmax
 alias for: bsl::uintmax
 
using difference_type = bsl::uintmax
 alias for: bsl::uintmax
 
using reference_type = T &
 alias for: T &
 
using const_reference_type = T const &
 alias for: T const &
 
using pointer_type = T *
 alias for: T *
 
using const_pointer_type = T const *
 alias for: T const *
 
using iterator_type = contiguous_iterator< T >
 alias for: contiguous_iterator<T>
 
using const_iterator_type = contiguous_iterator< T const >
 alias for: contiguous_iterator<T const>
 
using reverse_iterator_type = reverse_iterator< iterator_type >
 alias for: reverse_iterator<iterator>
 
using const_reverse_iterator_type = reverse_iterator< const_iterator_type >
 alias for: reverse_iterator<const_iterator>
 

Public Member Functions

constexpr pointer_type at_if (size_type const index) noexcept
 Returns a pointer to the instance of T stored at index "index". If the index is out of bounds, or the array is invalid, this function returns a nullptr. More...
 
constexpr const_pointer_type at_if (size_type const index) const noexcept
 Returns a pointer to the instance of T stored at index "index". If the index is out of bounds, or the array is invalid, this function returns a nullptr. More...
 
constexpr reference_type front () noexcept
 Returns a reference to the first element in the array. More...
 
constexpr const_reference_type front () const noexcept
 Returns a reference to the first element in the array. More...
 
constexpr pointer_type front_if () noexcept
 Returns a pointer to the first element in the array. More...
 
constexpr const_pointer_type front_if () const noexcept
 Returns a pointer to the first element in the array. More...
 
constexpr reference_type back () noexcept
 Returns a reference to the last element in the array. More...
 
constexpr const_reference_type back () const noexcept
 Returns a reference to the last element in the array. More...
 
constexpr pointer_type back_if () noexcept
 Returns a pointer to the last element in the array. More...
 
constexpr const_pointer_type back_if () const noexcept
 Returns a pointer to the last element in the array. More...
 
constexpr pointer_type data () noexcept
 Returns a pointer to the array being encapsulated. More...
 
constexpr const_pointer_type data () const noexcept
 Returns a pointer to the array being encapsulated. More...
 
constexpr iterator_type begin () noexcept
 Returns an iterator to the first element of the array. More...
 
constexpr const_iterator_type begin () const noexcept
 Returns an iterator to the first element of the array. More...
 
constexpr const_iterator_type cbegin () const noexcept
 Returns an iterator to the first element of the array. More...
 
constexpr iterator_type iter (size_type const i) noexcept
 Returns an iterator to the element "i" in the array. More...
 
constexpr const_iterator_type iter (size_type const i) const noexcept
 Returns an iterator to the element "i" in the array. More...
 
constexpr const_iterator_type citer (size_type const i) const noexcept
 Returns an iterator to the element "i" in the array. More...
 
constexpr iterator_type end () noexcept
 Returns an iterator to one past the last element of the array. If you attempt to access this iterator, a nullptr will always be returned. More...
 
constexpr const_iterator_type end () const noexcept
 Returns an iterator to one past the last element of the array. If you attempt to access this iterator, a nullptr will always be returned. More...
 
constexpr const_iterator_type cend () const noexcept
 Returns an iterator to one past the last element of the array. If you attempt to access this iterator, a nullptr will always be returned. More...
 
constexpr reverse_iterator_type rbegin () noexcept
 Returns a reverse iterator to one past the last element of the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr const_reverse_iterator_type rbegin () const noexcept
 Returns a reverse iterator to one past the last element of the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr const_reverse_iterator_type crbegin () const noexcept
 Returns a reverse iterator to one past the last element of the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr reverse_iterator_type riter (size_type const i) noexcept
 Returns a reverse iterator element "i" in the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr const_reverse_iterator_type riter (size_type const i) const noexcept
 Returns a reverse iterator element "i" in the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr const_reverse_iterator_type criter (size_type const i) const noexcept
 Returns a reverse iterator element "i" in the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr reverse_iterator_type rend () noexcept
 Returns a reverse iterator first element of the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr const_reverse_iterator_type rend () const noexcept
 Returns a reverse iterator first element of the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr const_reverse_iterator_type crend () const noexcept
 Returns a reverse iterator first element of the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 

Static Public Member Functions

static constexpr bool empty () noexcept
 Since arrays of size 0 are not allowed, always returns false. More...
 
static constexpr size_type size () noexcept
 Returns the number of elements in the array being encapsulated. More...
 
static constexpr size_type max_size () noexcept
 Returns the max number of elements the BSL supports. More...
 
static constexpr size_type size_bytes () noexcept
 Returns size() * sizeof(T) More...
 

Public Attributes

m_data [N]
 stores the array being wrapped
 

Related Functions

(Note that these are not member functions.)

template<typename T , bsl::uintmax N>
constexpr bool operator== (bsl::array< T, N > const &lhs, bsl::array< T, N > const &rhs) noexcept
 Returns true if two arrays contain the same contents. Returns false otherwise. More...
 
template<typename T , bsl::uintmax N>
constexpr bool operator!= (bsl::array< T, N > const &lhs, bsl::array< T, N > const &rhs) noexcept
 Returns false if two arrays contain the same contents. Returns true otherwise. More...
 

Detailed Description

template<typename T, bsl::uintmax N>
class bsl::array< T, N >

Provides a safe encapsulation for a C-style array, minicing the std::array APIs. This container is an aggregate type, but unlike a std::array, a bsl::array does not provide the T[n] syntax as this is nither Core Guideline compliant or compliant with AUTOSAR. Instead we provide at_if() versions which return a pointer to the element being requested. If the element does not exist, a nullptr is returned, providing a means to check for logic errors without the need for exceptions or failing fast which is not compliant with AUTOSAR. We also do not support N==0 type arrays and like other BSL classes, we do not support the member version of swap() and fill() as they are not compliant with AUTOSAR (due to the name reuse). User bsl::swap() and bsl::fill() instead.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_overview() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr, [](auto const &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Template Parameters
Tthe type of element being encapsulated.
Nthe total number of elements in the array. Cannot be 0

Member Function Documentation

◆ at_if() [1/2]

template<typename T, bsl::uintmax N>
constexpr pointer_type bsl::array< T, N >::at_if ( size_type const  index)
inlinenoexcept

Returns a pointer to the instance of T stored at index "index". If the index is out of bounds, or the array is invalid, this function returns a nullptr.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_at_if() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
if (auto const *const ptr = arr.at_if(0U)) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}

SUPPRESSION: PRQA 4024 - false positive

  • We suppress this because A9-3-1 states that we should not provide a non-const reference or pointer to private member function, unless the class mimics a smart pointer or a containter. This class mimics a container.
Parameters
indexthe index of the instance to return
Returns
Returns a pointer to the instance of T stored at index "index". If the index is out of bounds, or the array is invalid, this function returns a nullptr.

◆ at_if() [2/2]

template<typename T, bsl::uintmax N>
constexpr const_pointer_type bsl::array< T, N >::at_if ( size_type const  index) const
inlinenoexcept

Returns a pointer to the instance of T stored at index "index". If the index is out of bounds, or the array is invalid, this function returns a nullptr.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_at_if() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
if (auto const *const ptr = arr.at_if(0U)) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Parameters
indexthe index of the instance to return
Returns
Returns a pointer to the instance of T stored at index "index". If the index is out of bounds, or the array is invalid, this function returns a nullptr.

◆ front() [1/2]

template<typename T, bsl::uintmax N>
constexpr reference_type bsl::array< T, N >::front ( )
inlinenoexcept

Returns a reference to the first element in the array.

#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_front() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
if (val1 == arr.front()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns a reference to the first element in the array.

◆ front() [2/2]

template<typename T, bsl::uintmax N>
constexpr const_reference_type bsl::array< T, N >::front ( ) const
inlinenoexcept

Returns a reference to the first element in the array.

#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_front() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
if (val1 == arr.front()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns a reference to the first element in the array.

◆ front_if() [1/2]

template<typename T, bsl::uintmax N>
constexpr pointer_type bsl::array< T, N >::front_if ( )
inlinenoexcept

Returns a pointer to the first element in the array.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_front_if() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
if (auto const *const ptr = arr.front_if()) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Returns
Returns a pointer to the first element in the array.

◆ front_if() [2/2]

template<typename T, bsl::uintmax N>
constexpr const_pointer_type bsl::array< T, N >::front_if ( ) const
inlinenoexcept

Returns a pointer to the first element in the array.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_front_if() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
if (auto const *const ptr = arr.front_if()) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Returns
Returns a pointer to the first element in the array.

◆ back() [1/2]

template<typename T, bsl::uintmax N>
constexpr reference_type bsl::array< T, N >::back ( )
inlinenoexcept

Returns a reference to the last element in the array.

#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_back() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
if (val6 == arr.back()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns a reference to the last element in the array.

◆ back() [2/2]

template<typename T, bsl::uintmax N>
constexpr const_reference_type bsl::array< T, N >::back ( ) const
inlinenoexcept

Returns a reference to the last element in the array.

#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_back() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
if (val6 == arr.back()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns a reference to the last element in the array.

◆ back_if() [1/2]

template<typename T, bsl::uintmax N>
constexpr pointer_type bsl::array< T, N >::back_if ( )
inlinenoexcept

Returns a pointer to the last element in the array.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_back_if() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
if (auto const *const ptr = arr.back_if()) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Returns
Returns a pointer to the last element in the array.

◆ back_if() [2/2]

template<typename T, bsl::uintmax N>
constexpr const_pointer_type bsl::array< T, N >::back_if ( ) const
inlinenoexcept

Returns a pointer to the last element in the array.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_back_if() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
if (auto const *const ptr = arr.back_if()) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Returns
Returns a pointer to the last element in the array.

◆ data() [1/2]

template<typename T, bsl::uintmax N>
constexpr pointer_type bsl::array< T, N >::data ( )
inlinenoexcept

Returns a pointer to the array being encapsulated.

#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_data() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
if (nullptr != arr.data()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns a pointer to the array being encapsulated.

◆ data() [2/2]

template<typename T, bsl::uintmax N>
constexpr const_pointer_type bsl::array< T, N >::data ( ) const
inlinenoexcept

Returns a pointer to the array being encapsulated.

#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_data() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
if (nullptr != arr.data()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns a pointer to the array being encapsulated.

◆ begin() [1/2]

template<typename T, bsl::uintmax N>
constexpr iterator_type bsl::array< T, N >::begin ( )
inlinenoexcept

Returns an iterator to the first element of the array.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_begin() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.begin(), arr.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns an iterator to the first element of the array.

◆ begin() [2/2]

template<typename T, bsl::uintmax N>
constexpr const_iterator_type bsl::array< T, N >::begin ( ) const
inlinenoexcept

Returns an iterator to the first element of the array.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_begin() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.begin(), arr.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns an iterator to the first element of the array.

◆ cbegin()

template<typename T, bsl::uintmax N>
constexpr const_iterator_type bsl::array< T, N >::cbegin ( ) const
inlinenoexcept

Returns an iterator to the first element of the array.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_begin() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.begin(), arr.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns an iterator to the first element of the array.

◆ iter() [1/2]

template<typename T, bsl::uintmax N>
constexpr iterator_type bsl::array< T, N >::iter ( size_type const  i)
inlinenoexcept

Returns an iterator to the element "i" in the array.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_iter() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.iter(i1), arr.iter(i4), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the array to return an iterator for.
Returns
Returns an iterator to the element "i" in the array.

◆ iter() [2/2]

template<typename T, bsl::uintmax N>
constexpr const_iterator_type bsl::array< T, N >::iter ( size_type const  i) const
inlinenoexcept

Returns an iterator to the element "i" in the array.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_iter() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.iter(i1), arr.iter(i4), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the array to return an iterator for.
Returns
Returns an iterator to the element "i" in the array.

◆ citer()

template<typename T, bsl::uintmax N>
constexpr const_iterator_type bsl::array< T, N >::citer ( size_type const  i) const
inlinenoexcept

Returns an iterator to the element "i" in the array.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_iter() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.iter(i1), arr.iter(i4), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the array to return an iterator for.
Returns
Returns an iterator to the element "i" in the array.

◆ end() [1/2]

template<typename T, bsl::uintmax N>
constexpr iterator_type bsl::array< T, N >::end ( )
inlinenoexcept

Returns an iterator to one past the last element of the array. If you attempt to access this iterator, a nullptr will always be returned.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_end() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.begin(), arr.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns an iterator to one past the last element of the array. If you attempt to access this iterator, a nullptr will always be returned.

◆ end() [2/2]

template<typename T, bsl::uintmax N>
constexpr const_iterator_type bsl::array< T, N >::end ( ) const
inlinenoexcept

Returns an iterator to one past the last element of the array. If you attempt to access this iterator, a nullptr will always be returned.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_end() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.begin(), arr.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns an iterator to one past the last element of the array. If you attempt to access this iterator, a nullptr will always be returned.

◆ cend()

template<typename T, bsl::uintmax N>
constexpr const_iterator_type bsl::array< T, N >::cend ( ) const
inlinenoexcept

Returns an iterator to one past the last element of the array. If you attempt to access this iterator, a nullptr will always be returned.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_end() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.begin(), arr.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns an iterator to one past the last element of the array. If you attempt to access this iterator, a nullptr will always be returned.

◆ rbegin() [1/2]

template<typename T, bsl::uintmax N>
constexpr reverse_iterator_type bsl::array< T, N >::rbegin ( )
inlinenoexcept

Returns a reverse iterator to one past the last element of the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_rbegin() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.rbegin(), arr.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator to the last element of the array.

◆ rbegin() [2/2]

template<typename T, bsl::uintmax N>
constexpr const_reverse_iterator_type bsl::array< T, N >::rbegin ( ) const
inlinenoexcept

Returns a reverse iterator to one past the last element of the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_rbegin() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.rbegin(), arr.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator to the last element of the array.

◆ crbegin()

template<typename T, bsl::uintmax N>
constexpr const_reverse_iterator_type bsl::array< T, N >::crbegin ( ) const
inlinenoexcept

Returns a reverse iterator to one past the last element of the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_rbegin() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.rbegin(), arr.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator to the last element of the array.

◆ riter() [1/2]

template<typename T, bsl::uintmax N>
constexpr reverse_iterator_type bsl::array< T, N >::riter ( size_type const  i)
inlinenoexcept

Returns a reverse iterator element "i" in the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_riter() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.riter(i4), arr.riter(i1), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the array to return an iterator for.
Returns
Returns a reverse iterator element "i" in the array.

◆ riter() [2/2]

template<typename T, bsl::uintmax N>
constexpr const_reverse_iterator_type bsl::array< T, N >::riter ( size_type const  i) const
inlinenoexcept

Returns a reverse iterator element "i" in the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_riter() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.riter(i4), arr.riter(i1), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the array to return an iterator for.
Returns
Returns a reverse iterator element "i" in the array.

◆ criter()

template<typename T, bsl::uintmax N>
constexpr const_reverse_iterator_type bsl::array< T, N >::criter ( size_type const  i) const
inlinenoexcept

Returns a reverse iterator element "i" in the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_riter() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.riter(i4), arr.riter(i1), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the array to return an iterator for.
Returns
Returns a reverse iterator element "i" in the array.

◆ rend() [1/2]

template<typename T, bsl::uintmax N>
constexpr reverse_iterator_type bsl::array< T, N >::rend ( )
inlinenoexcept

Returns a reverse iterator first element of the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_rend() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.rbegin(), arr.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator first element of the array.

◆ rend() [2/2]

template<typename T, bsl::uintmax N>
constexpr const_reverse_iterator_type bsl::array< T, N >::rend ( ) const
inlinenoexcept

Returns a reverse iterator first element of the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_rend() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.rbegin(), arr.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator first element of the array.

◆ crend()

template<typename T, bsl::uintmax N>
constexpr const_reverse_iterator_type bsl::array< T, N >::crend ( ) const
inlinenoexcept

Returns a reverse iterator first element of the array. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [N - 1, 0) while internally storing the range [N, 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_rend() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::for_each(arr.rbegin(), arr.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator first element of the array.

◆ empty()

template<typename T, bsl::uintmax N>
static constexpr bool bsl::array< T, N >::empty ( )
inlinestaticnoexcept

Since arrays of size 0 are not allowed, always returns false.

#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_empty() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
if (!arr.empty()) {
bsl::print() << "success\n";
}
}
}
Returns
Since arrays of size 0 are not allowed, always returns false.

◆ size()

template<typename T, bsl::uintmax N>
static constexpr size_type bsl::array< T, N >::size ( )
inlinestaticnoexcept

Returns the number of elements in the array being encapsulated.

#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_size() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::print() << "size: " << arr.size() << bsl::endl;
}
}
Returns
Returns the number of elements in the array being encapsulated.

◆ max_size()

template<typename T, bsl::uintmax N>
static constexpr size_type bsl::array< T, N >::max_size ( )
inlinestaticnoexcept

Returns the max number of elements the BSL supports.

#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_max_size() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::print() << "max size: " << arr.max_size() << bsl::endl;
}
}
Returns
Returns the max number of elements the BSL supports.

◆ size_bytes()

template<typename T, bsl::uintmax N>
static constexpr size_type bsl::array< T, N >::size_bytes ( )
inlinestaticnoexcept

Returns size() * sizeof(T)

#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_size_bytes() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::print() << "size in bytes: " << arr.size_bytes() << bsl::endl;
}
}
Returns
Returns size() * sizeof(T)

Friends And Related Function Documentation

◆ operator==()

template<typename T , bsl::uintmax N>
constexpr bool operator== ( bsl::array< T, N > const &  lhs,
bsl::array< T, N > const &  rhs 
)
related

Returns true if two arrays contain the same contents. Returns false otherwise.

#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_equals() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr1{val1, val2, val3, val4, val5, val6};
bsl::array<bsl::uintmax, size> const arr2{val1, val2, val3, val4, val5, val6};
bsl::array<bsl::uintmax, size> const arr3{val1, val1, val1, val1, val1, val1};
if (arr1 == arr2) {
bsl::print() << "success\n";
}
if (arr1 != arr3) {
bsl::print() << "success\n";
}
}
}
Template Parameters
Tthe type of element being encapsulated.
Nthe total number of elements in the array. Cannot be 0
Parameters
lhsthe left hand side of the operation
rhsthe right hand side of the operation
Returns
Returns true if two arrays contain the same contents. Returns false otherwise.

◆ operator!=()

template<typename T , bsl::uintmax N>
constexpr bool operator!= ( bsl::array< T, N > const &  lhs,
bsl::array< T, N > const &  rhs 
)
related

Returns false if two arrays contain the same contents. Returns true otherwise.

#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_array_not_equals() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr1{val1, val2, val3, val4, val5, val6};
bsl::array<bsl::uintmax, size> const arr2{val1, val2, val3, val4, val5, val6};
bsl::array<bsl::uintmax, size> const arr3{val1, val1, val1, val1, val1, val1};
if (arr1 == arr2) {
bsl::print() << "success\n";
}
if (arr1 != arr3) {
bsl::print() << "success\n";
}
}
}
Template Parameters
Tthe type of element being encapsulated.
Nthe total number of elements in the array. Cannot be 0
Parameters
lhsthe left hand side of the operation
rhsthe right hand side of the operation
Returns
Returns true if two arrays have the same size and contain the same contents. Returns false otherwise.

The documentation for this class was generated from the following file: