35#ifndef _BLAZE_UTIL_SMALLARRAY_H_
36#define _BLAZE_UTIL_SMALLARRAY_H_
80 ,
typename A = std::allocator<T> >
82 :
private SmallArrayData<T,N>
99 explicit inline SmallArray(
const A& alloc = A() );
100 explicit inline SmallArray(
size_t n,
const A& alloc = A() );
101 inline SmallArray(
size_t n,
const T& init,
const A& alloc = A() );
103 template<
typename InputIt >
104 inline SmallArray( InputIt first, InputIt last,
const A& alloc = A() );
106 template<
typename U >
107 inline SmallArray( initializer_list<U> list,
const A& alloc = A() );
142 template< typename U >
143 inline
SmallArray& operator=( initializer_list<U> list );
153 inline
bool empty() const noexcept;
154 inline
size_t size() const noexcept;
155 inline
size_t capacity() const noexcept;
159 void resize(
size_t n, const T& value );
269 std::uninitialized_fill(
begin_,
end_, init );
284template<
typename InputIt >
288 std::uninitialized_copy( first, last,
begin_ );
312template<
typename U >
316 std::uninitialized_copy( list.begin(), list.end(),
begin_ );
347 : begin_( sa.begin_ )
349 , final_( sa.final_ )
351 if( !sa.isDynamic() ) {
359 sa.begin_ = sa.array();
361 sa.final_ = sa.begin_ + N;
446 return begin_[index];
467 return begin_[index];
488 if( index >=
size() ) {
491 return begin_[index];
512 if( index >=
size() ) {
515 return begin_[index];
679template<
typename U >
683 std::copy( list.begin(), list.end(), begin_ );
705 std::copy( rhs.
begin(), rhs.
end(), begin_ );
724 std::move( rhs.begin_, rhs.end_, begin_ );
727 rhs.begin_ = rhs.array();
728 rhs.end_ = rhs.begin_;
729 rhs.final_ = rhs.begin_ + N;
754 return begin_ == end_;
769 return static_cast<size_t>( end_ - begin_ );
784 return final_ - begin_;
807 begin_ = this->array();
835 else if( n <
size() )
863 std::uninitialized_fill( begin_+
size(), begin_+n, value );
866 else if( n <
size() )
889 const size_t oldCapacity(
capacity() );
891 if( n > oldCapacity )
893 const size_t oldSize(
size() );
896 if( IsNothrowMoveConstructible_v<T> ) {
900 std::uninitialized_copy( begin_, end_, tmp );
910 end_ = tmp + oldSize;
931 const size_t oldCapacity(
capacity() );
932 const size_t oldSize (
size() );
934 if( isDynamic() && oldCapacity > oldSize )
938 if( IsNothrowMoveConstructible_v<T> ) {
942 std::uninitialized_copy( begin_, end_, tmp );
948 final_ = tmp + oldSize;
969 const size_t oldCapacity(
capacity() );
971 if(
size() == oldCapacity ) {
972 reserve(
max( 2UL*oldCapacity, 7UL ) );
975 ::new ( end_ ) T( value );
994 const size_t oldCapacity(
capacity() );
996 if(
size() == oldCapacity ) {
997 reserve(
max( 2UL*oldCapacity, 7UL ) );
1000 ::new ( end_ ) T( std::move( value ) );
1019 const size_t oldCapacity(
capacity() );
1020 const size_t oldSize (
size() );
1022 if( oldSize == oldCapacity )
1024 const size_t newCapacity(
max( 1UL, 2UL*oldCapacity ) );
1025 const size_t index( pos - begin_ );
1027 T* tmp (
allocate( newCapacity ) );
1028 T* newpos( tmp + index );
1031 ::new ( newpos ) T( value );
1039 final_ = tmp + newCapacity;
1040 end_ = tmp + oldSize + 1UL;
1045 else if( pos == end_ )
1047 ::new( pos ) T( value );
1053 const auto tmp( end_ - 1UL );
1054 ::new ( end_ ) T( std::move( *tmp ) );
1057 std::move_backward( pos, tmp, end_ );
1059 ::new ( pos ) T( value );
1086 const size_t oldCapacity(
capacity() );
1087 const size_t oldSize (
size() );
1089 if( oldSize == oldCapacity )
1091 const size_t newCapacity(
max( 1UL, 2UL*oldCapacity ) );
1092 const size_t index( pos - begin_ );
1094 T* tmp (
allocate( newCapacity ) );
1095 T* newpos( tmp + index );
1098 ::new ( newpos ) T( std::move( value ) );
1106 final_ = tmp + newCapacity;
1107 end_ = tmp + oldSize + 1UL;
1112 else if( pos == end_ )
1114 ::new( pos ) T( std::move( value ) );
1120 const auto tmp( end_ - 1UL );
1121 ::new ( end_ ) T( std::move( *tmp ) );
1124 std::move_backward( pos, tmp, end_ );
1126 ::new ( pos ) T( std::move( value ) );
1154 std::move( pos+1UL, end_, pos );
1180 const size_t n( last - first );
1182 std::move( last, end_, first );
1208 if( isDynamic() && sa.isDynamic() )
1210 swap( begin_, sa.begin_ );
1211 swap( end_ , sa.end_ );
1212 swap( final_, sa.final_ );
1214 else if( isDynamic() )
1216 const size_t n( sa.size() );
1225 begin_ = this->array();
1227 final_ = begin_ + N;
1229 else if( sa.isDynamic() )
1231 const size_t n(
size() );
1240 sa.begin_ = sa.array();
1241 sa.end_ = sa.begin_ + n;
1242 sa.final_ = sa.begin_ + N;
1244 else if(
size() > sa.size() )
1246 const size_t n(
size() - sa.size() );
1247 const auto pos = std::swap_ranges( sa.begin_, sa.end_, begin_ );
1256 const size_t n( sa.size() -
size() );
1257 const auto pos = std::swap_ranges( begin_, end_, sa.begin_ );
1278 return ( N == 0UL || begin_ != this->array() );
1294template<
typename T1,
size_t N1,
typename A1,
typename T2,
size_t N2,
typename A2 >
1297template<
typename T1,
size_t N1,
typename A1,
typename T2,
size_t N2,
typename A2 >
1300template<
typename T,
size_t N,
typename A >
1303template<
typename T,
size_t N,
typename A >
1306template<
typename T,
size_t N,
typename A >
1309template<
typename T,
size_t N,
typename A >
1312template<
typename T,
size_t N,
typename A >
1315template<
typename T,
size_t N,
typename A >
1318template<
typename T,
size_t N,
typename A >
1321template<
typename T,
size_t N,
typename A >
1323 noexcept( IsNothrowMoveConstructible_v<T> );
1336template<
typename T1
1344 if( lhs.
size() != rhs.
size() )
return false;
1359template<
typename T1
1367 return !( lhs == rhs );
1379template<
typename T,
size_t N,
typename A >
1394template<
typename T,
size_t N,
typename A >
1409template<
typename T,
size_t N,
typename A >
1424template<
typename T,
size_t N,
typename A >
1439template<
typename T,
size_t N,
typename A >
1454template<
typename T,
size_t N,
typename A >
1495 noexcept( IsNothrowMoveConstructible_v<T> )
Header file for run time assertion macros.
Constraint on the data type.
Header file for the generic destroy_at algorithm.
Header file for the generic destroy algorithm.
Header file for the IsAssignable type trait.
Header file for the IsConstructible type trait.
Header file for the SmallArrayData class template.
Header file for the generic uninitialized_default_construct algorithm.
Header file for the generic uninitialized_move algorithm.
Constraint on the data type.
Implementation of a dynamic array with small array optimization.
Definition: SmallArray.h:84
ConstIterator cbegin() const noexcept
Returns an iterator to the first element of the small array.
Definition: SmallArray.h:597
void pushBack(const T &value)
Adding an element to the end of the small array.
Definition: SmallArray.h:965
Reference operator[](size_t index) noexcept
Subscript operator for the direct access to the array elements.
Definition: SmallArray.h:443
T * begin_
Pointer to the beginning of the currently used storage.
Definition: SmallArray.h:199
Iterator insert(Iterator pos, const T &value)
Inserting an element at the specified position into the small array.
Definition: SmallArray.h:1017
void reserve(size_t n)
Setting the minimum capacity of the array.
Definition: SmallArray.h:887
void shrinkToFit()
Requesting the removal of unused capacity.
Definition: SmallArray.h:929
const T * ConstPointer
Pointer to a constant array element.
Definition: SmallArray.h:89
T * final_
Pointer to the very end of the currently used storage.
Definition: SmallArray.h:201
Pointer data() noexcept
Low-level data access to the array elements.
Definition: SmallArray.h:531
ConstIterator cend() const noexcept
Returns an iterator just past the last element of the small array.
Definition: SmallArray.h:645
size_t capacity() const noexcept
Returns the maximum capacity of the small array.
Definition: SmallArray.h:782
T * Pointer
Pointer to a non-constant array element.
Definition: SmallArray.h:88
T ElementType
Type of the array elements.
Definition: SmallArray.h:87
bool isDynamic() const noexcept
Returns whether the small array uses its dynamic storage.
Definition: SmallArray.h:1276
void resize(size_t n)
Changing the size of the array.
Definition: SmallArray.h:827
T & Reference
Reference to a non-constant array element.
Definition: SmallArray.h:90
Reference at(size_t index)
Checked access to the array elements.
Definition: SmallArray.h:486
Iterator begin() noexcept
Returns an iterator to the first element of the small array.
Definition: SmallArray.h:565
T * end_
Pointer to the end of the currently used storage.
Definition: SmallArray.h:200
Iterator end() noexcept
Returns an iterator just past the last element of the small array.
Definition: SmallArray.h:613
void swap(SmallArray &sa) noexcept(IsNothrowMoveConstructible_v< T >)
Swapping the contents of two small arrays.
Definition: SmallArray.h:1204
const T * ConstIterator
Iterator over constant elements.
Definition: SmallArray.h:93
bool empty() const noexcept
Returns whether the array is empty.
Definition: SmallArray.h:752
T * Iterator
Iterator over non-constant elements.
Definition: SmallArray.h:92
void clear()
Clearing the array.
Definition: SmallArray.h:799
const T & ConstReference
Reference to a constant array element.
Definition: SmallArray.h:91
size_t size() const noexcept
Returns the current size/dimension of the small array.
Definition: SmallArray.h:767
Iterator erase(Iterator pos)
Erasing an element from the small array.
Definition: SmallArray.h:1152
SmallArray(const A &alloc=A())
The (default) constructor for SmallArray.
Definition: SmallArray.h:231
~SmallArray()
The destructor for SmallArray.
Definition: SmallArray.h:410
void destroy(ForwardIt first, ForwardIt last)
Destroys the given range of objects .
Definition: Destroy.h:67
void uninitialized_default_construct(ForwardIt first, ForwardIt last)
Default constructs elements in the given range.
Definition: UninitializedDefaultConstruct.h:69
ForwardIt uninitialized_move(InputIt first, InputIt last, ForwardIt dest)
Move the elements from the given source range to the uninitialized destination range.
Definition: UninitializedMove.h:72
void destroy_at(T *p) noexcept
Destroys the object at the given address.
Definition: DestroyAt.h:57
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.
Definition: Volatile.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.
Definition: Const.h:79
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1375
size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:692
void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:1108
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:676
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.
Definition: Assert.h:117
bool equal(const SharedValue< T1 > &lhs, const SharedValue< T2 > &rhs)
Equality check for a two shared values.
Definition: SharedValue.h:343
constexpr bool IsNothrowMoveConstructible_v
Auxiliary variable template for the IsNothrowMoveConstructible type trait.
Definition: IsConstructible.h:427
void deallocate(T *address) noexcept
Deallocation of memory for built-in data types.
Definition: Memory.h:230
SmallArray< T, N, A >::ConstIterator begin(const SmallArray< T, N, A > &sa)
Returns an iterator to the first element of the given small array.
Definition: SmallArray.h:1395
SmallArray< T, N, A >::ConstIterator cbegin(const SmallArray< T, N, A > &sa)
Returns an iterator to the first element of the given small array.
Definition: SmallArray.h:1410
SmallArray< T, N, A >::ConstIterator cend(const SmallArray< T, N, A > &sa)
Returns an iterator just past the last element of the given small array.
Definition: SmallArray.h:1455
void swap(SmallArray< T, N, A > &a, SmallArray< T, N, A > &b) noexcept(IsNothrowMoveConstructible_v< T >)
Swapping the contents of two small arrays.
Definition: SmallArray.h:1494
bool operator==(const SmallArray< T1, N1, A1 > &lhs, const SmallArray< T2, N2, A2 > &rhs)
Equality operator for the comparison of two dense arrays.
Definition: SmallArray.h:1342
void clear(SmallArray< T, N, A > &sa)
Clearing the given small array.
Definition: SmallArray.h:1472
bool operator!=(const SmallArray< T1, N1, A1 > &lhs, const SmallArray< T2, N2, A2 > &rhs)
Inequality operator for the comparison of two dense arrays.
Definition: SmallArray.h:1365
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
T * allocate(size_t size)
Aligned array allocation for built-in data types.
Definition: Memory.h:158
SmallArray< T, N, A >::ConstIterator end(const SmallArray< T, N, A > &sa)
Returns an iterator just past the last element of the given small array.
Definition: SmallArray.h:1440
Definition of the nested auxiliary struct Uninitialized.
Definition: SmallArray.h:176
Header file for exception macros.
Header file for the initializer_list template.
Header file for basic type definitions.
Header file for the generic max algorithm.