17 #ifdef LVARRAY_BOUNDS_CHECK 24 #define ARRAYMANIPULATION_CHECK_BOUNDS( index ) \ 25 LVARRAY_ERROR_IF( !isPositive( index ) || index >= size, \ 26 "Array Bounds Check Failed: index=" << index << " size()=" << size ) 33 #define ARRAYMANIPULATION_CHECK_INSERT_BOUNDS( index ) \ 34 LVARRAY_ERROR_IF( !isPositive( index ) || index > size, \ 35 "Array Bounds Insert Check Failed: index=" << index << " size()=" << size ) 37 #else // LVARRAY_BOUNDS_CHECK 44 #define ARRAYMANIPULATION_CHECK_BOUNDS( index ) 51 #define ARRAYMANIPULATION_CHECK_INSERT_BOUNDS( index ) 53 #endif // LVARRAY_BOUNDS_CHECK 65 namespace arrayManipulation
73 template<
typename INDEX_TYPE >
75 typename std::enable_if< std::is_signed< INDEX_TYPE >::value,
bool >::type
83 template<
typename INDEX_TYPE >
85 typename std::enable_if< !std::is_signed< INDEX_TYPE >::value,
bool >::type
96 template<
typename ITER >
98 typename std::iterator_traits< ITER >::difference_type
99 iterDistance( ITER first, ITER
const last, std::input_iterator_tag )
101 typename std::iterator_traits< ITER >::difference_type n = 0;
102 while( first != last )
118 template<
typename RandomAccessIterator >
120 typename std::iterator_traits< RandomAccessIterator >::difference_type
121 iterDistance( RandomAccessIterator first, RandomAccessIterator last, std::random_access_iterator_tag )
122 {
return last - first; }
131 template<
typename ITER >
133 typename std::iterator_traits< ITER >::difference_type
135 {
return iterDistance( first, last,
typename std::iterator_traits< ITER >::iterator_category() ); }
144 template<
typename T >
147 std::ptrdiff_t
const size )
151 for( std::ptrdiff_t i = 0; i < size; ++i )
166 template<
typename ITER,
typename T >
170 T * LVARRAY_RESTRICT dst )
174 while( first != last )
176 new ( dst ) T( *first );
190 template<
typename T >
193 std::ptrdiff_t
const size,
194 T *
const LVARRAY_RESTRICT src )
200 for( std::ptrdiff_t i = 0; i < size; ++i )
202 new (dst + i) T( std::move( src[ i ] ) );
214 template<
typename T >
217 std::ptrdiff_t
const size,
218 std::ptrdiff_t
const amount )
227 for( std::ptrdiff_t j = 0; j < size; ++j )
229 new ( ptr + j - amount ) T( std::move( ptr[ j ] ) );
242 template<
typename T >
245 std::ptrdiff_t
const size,
246 std::ptrdiff_t
const amount )
255 for( std::ptrdiff_t j = size - 1; j >= 0; --j )
257 new ( ptr + amount + j ) T( std::move( ptr[ j ] ) );
272 template<
typename T,
typename ... ARGS >
274 void resize( T *
const LVARRAY_RESTRICT ptr,
275 std::ptrdiff_t
const size,
276 std::ptrdiff_t
const newSize,
284 destroy( ptr + newSize, size - newSize );
287 for( std::ptrdiff_t i = size; i < newSize; ++i )
289 new ( ptr + i ) T( std::forward< ARGS >( args )... );
303 template<
typename T >
306 std::ptrdiff_t
const size,
307 std::ptrdiff_t
const index,
308 std::ptrdiff_t
const n )
319 for( std::ptrdiff_t i = size; i > index; --i )
321 std::ptrdiff_t
const curIndex = i - 1;
322 new ( ptr + curIndex + n ) T( std::move( ptr[ curIndex ] ) );
326 std::ptrdiff_t
const bounds = (index + n < size) ? index + n : size;
327 destroy( ptr + index, bounds - index );
340 template<
typename T >
343 std::ptrdiff_t
const size,
344 std::ptrdiff_t
const index,
345 std::ptrdiff_t
const n )
357 for( std::ptrdiff_t i = index; i < size; ++i )
359 ptr[i - n] = std::move( ptr[i] );
373 template<
typename T >
375 void erase( T *
const LVARRAY_RESTRICT ptr,
376 std::ptrdiff_t
const size,
377 std::ptrdiff_t
const index,
378 std::ptrdiff_t
const n=1 )
387 shiftDown( ptr, size, std::ptrdiff_t( index + n ), n );
402 template<
typename T,
typename ... ARGS >
405 std::ptrdiff_t
const size,
410 new ( ptr + size ) T( std::forward< ARGS >( args ) ... );
424 template<
typename T,
typename ITER >
426 std::ptrdiff_t
append( T *
const LVARRAY_RESTRICT ptr,
427 std::ptrdiff_t
const size,
434 std::ptrdiff_t i = 0;
435 while( first != last )
437 new( ptr + size + i ) T( *first );
455 template<
typename T,
typename ... ARGS >
458 std::ptrdiff_t
const size,
459 std::ptrdiff_t
const index,
467 shiftUp( ptr, size, index, std::ptrdiff_t( 1 ) );
468 new ( ptr + index ) T( std::forward< ARGS >( args ) ... );
482 template<
typename T,
typename ITERATOR >
484 void insert( T *
const LVARRAY_RESTRICT ptr,
485 std::ptrdiff_t
const size,
486 std::ptrdiff_t
const index,
488 std::ptrdiff_t
const n )
494 shiftUp( ptr, size, index, n );
496 for( std::ptrdiff_t i = 0; i < n; ++i )
498 new ( ptr + index + i ) T( *first );
510 template<
typename T >
513 std::ptrdiff_t
const size )
517 ptr[ size - 1 ].~T();
#define LVARRAY_ASSERT(EXP)
Assert EXP is true with no message.
constexpr std::iterator_traits< ITER >::difference_type iterDistance(ITER first, ITER const last, std::input_iterator_tag)
void uninitializedShiftUp(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const amount)
Shift values up into uninitialized memory.
void uninitializedMove(T *const LVARRAY_RESTRICT dst, std::ptrdiff_t const size, T *const LVARRAY_RESTRICT src)
Move construct values from the source to the destination.
void shiftUp(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, std::ptrdiff_t const n)
Shift the values in the array at or above the given position up by the given amount. New uninitialized values take their place.
constexpr std::enable_if< std::is_signed< INDEX_TYPE >::value, bool >::type isPositive(INDEX_TYPE const i)
void destroy(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size)
Destory the values in the array.
void uninitializedCopy(ITER first, ITER const &last, T *LVARRAY_RESTRICT dst)
Copy construct values from the source to the destination.
#define ARRAYMANIPULATION_CHECK_BOUNDS(index)
Check that index is a valid into into the array.
void emplace(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, ARGS &&... args)
Insert into the array constructing the new value in place.
void popBack(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size)
Destroy the value at the end of the array.
std::ptrdiff_t append(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, ITER first, ITER const last)
Append the given values to the array.
void resize(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const newSize, ARGS &&... args)
Resize the give array.
Contains a bunch of macro definitions.
void uninitializedShiftDown(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const amount)
Shift values down into uninitialized memory.
void erase(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, std::ptrdiff_t const n=1)
Shift the values in the array at or above the given position down by the given amount overwriting the...
void emplaceBack(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, ARGS &&... args)
Append the to the array constructing the new value in place.
void shiftDown(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, std::ptrdiff_t const n)
Shift the values in the array at or above the given position down by the given amount overwriting the...
#define DISABLE_HD_WARNING
Disable host device warnings.
#define ARRAYMANIPULATION_CHECK_INSERT_BOUNDS(index)
Check that index is a valid insertion position in the array.
void insert(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, ITERATOR first, std::ptrdiff_t const n)
Insert the given values into the array at the given position.
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.