16#ifndef __BE_MEMORY_AUTOARRAY_H__
17#define __BE_MEMORY_AUTOARRAY_H__
155 ptrdiff_t index)
const;
382 std::initializer_list<T> ilist);
420 std::swap(std::declval<value_type&>(),
421 std::declval<value_type&>()))
424 std::swap(std::declval<size_type&>(),
425 std::declval<size_type&>())));
509 if (!free && (new_size <= _capacity)) {
514 T* new_data =
nullptr;
516 new_data =
new (std::nothrow) T[new_size];
517 if (new_data ==
nullptr)
522 std::copy(&_data[0], &_data[((new_size < _size) ? new_size : _size)],
526 if (_data !=
nullptr)
529 _size = _capacity = new_size;
537 std::copy(&buffer[0], &buffer[_size], _data);
547 std::copy(&buffer[0], &buffer[size], _data);
553 ptrdiff_t index)
const
556 throw std::out_of_range(
"index");
558 return (_data[index]);
560 throw std::out_of_range(
"index");
569 throw std::out_of_range(
"index");
571 return (_data[index]);
573 throw std::out_of_range(
"index");
577typename std::vector<T>
581 return {this->cbegin(), this->cend()};
608 return (_data[index]);
617 return (_data[index]);
625 if (
this != &other) {
626 _size = _capacity = other._size;
627 if (_data !=
nullptr) {
632 _data =
new (std::nothrow) T[_size];
633 if (_data ==
nullptr)
636 std::copy(&(other._data[0]), &(other._data[_size]),
650 std::swap(std::declval<value_type&>(), std::declval<value_type&>())) &&
652 std::swap(std::declval<size_type&>(), std::declval<size_type&>())))
656 swap(_size, other._size);
657 swap(_capacity, other._capacity);
658 swap(_data, other._data);
678 return (this->cbegin());
696 "large to represent end iterator"};
708 return (this->cend());
719 "large to represent end iterator"};
737 _data =
new (std::nothrow) T[_size];
738 if (_data ==
nullptr)
748 _capacity(copy._size)
751 _data =
new (std::nothrow) T[_size];
752 if (_data ==
nullptr)
754 std::copy(&(
copy._data[0]), &(
copy._data[_size]), _data);
764 _capacity(rvalue._capacity)
767 rvalue._data =
nullptr;
768 rvalue._capacity = 0;
774 std::initializer_list<T> ilist) :
AutoArray(ilist.size())
776 std::copy(ilist.begin(), ilist.end(), _data);
785 if (_data !=
nullptr)
811 return (!(lhs == rhs));
820 return (std::lexicographical_compare(lhs.
cbegin(), lhs.
cend(),
830 return (!(rhs < lhs));
848 return (!(lhs < rhs));
An error occurred when allocating an object.
A StrategyError object is thrown when the underlying implementation of this interface encounters an e...
A C-style array wrapped in the facade of a C++ STL container.
const_iterator begin() const
Obtain an iterator to the beginning of the AutoArray.
void copy(const T *buffer, size_type size)
Deep-copy the contents of a buffer into this AutoArray.
T & reference
Reference to element.
AutoArray(const AutoArray ©)
Construct an AutoArray.
const_reference at(ptrdiff_t index) const
Subscript into the AutoArray with checked access.
AutoArray & operator=(const AutoArray &other)
Copy assignment operator overload performing a deep copy.
iterator end()
Obtain an iterator to the end of the AutoArray.
iterator begin()
Obtain an iterator to the beginning of the AutoArray.
AutoArray(size_type size=0)
Construct an AutoArray.
AutoArray & operator=(AutoArray &&other) noexcept(noexcept(std::swap(std::declval< value_type & >(), std::declval< value_type & >())) &&noexcept(std::swap(std::declval< size_type & >(), std::declval< size_type & >())))
Move assignment operator.
const_iterator cend() const
Obtain an iterator to the end of the AutoArray.
void copy(const T *buffer)
Deep-copy the contents of a buffer into this AutoArray.
const_iterator cbegin() const
Obtain an iterator to the beginning of the AutoArray.
const T & const_reference
Const reference element.
size_type size() const
Obtain the number of accessible elements.
reference operator[](ptrdiff_t index)
Subscripting operator overload with unchecked access.
std::vector< T > to_vector() const
Obtain a copy of elements in this AutoArray as a vector.
AutoArray(AutoArray &&rvalue) noexcept
Construct an AutoArray.
size_t size_type
Type of subscripts, counts, etc.
const_iterator end() const
Obtain an iterator to the end of the AutoArray.
T value_type
Type of element.
const_reference operator[](ptrdiff_t index) const
Const subscripting operator overload with unchecked access.
reference at(ptrdiff_t index)
Subscript into the AutoArray with checked access.
void resize(size_type new_size, bool free=false)
Change the number of accessible elements.
AutoArray(std::initializer_list< T > ilist)
Construct an AutoArray.
RandomAccessIterator for any AutoArray.
std::ptrdiff_t difference_type
Type used to measure distance between iterators.
bool operator==(const AutoArray< T > &lhs, const AutoArray< T > &rhs)
bool operator<(const AutoArray< T > &lhs, const AutoArray< T > &rhs)
bool operator<=(const AutoArray< T > &lhs, const AutoArray< T > &rhs)
bool operator>(const AutoArray< T > &lhs, const AutoArray< T > &rhs)
bool operator>=(const AutoArray< T > &lhs, const AutoArray< T > &rhs)
bool operator!=(const AutoArray< T > &lhs, const AutoArray< T > &rhs)
This software was developed at the National Institute of Standards and Technology (NIST) by employees...