23 #ifdef LVARRAY_BOUNDS_CHECK 30 #define ARRAYMANIPULATION_CHECK_BOUNDS( index ) \ 31 LVARRAY_ERROR_IF( !isPositive( index ) || index >= size, \ 32 "Array Bounds Check Failed: index=" << index << " size()=" << size ) 39 #define ARRAYMANIPULATION_CHECK_INSERT_BOUNDS( index ) \ 40 LVARRAY_ERROR_IF( !isPositive( index ) || index > size, \ 41 "Array Bounds Insert Check Failed: index=" << index << " size()=" << size ) 43 #else // LVARRAY_BOUNDS_CHECK 50 #define ARRAYMANIPULATION_CHECK_BOUNDS( index ) 57 #define ARRAYMANIPULATION_CHECK_INSERT_BOUNDS( index ) 59 #endif // LVARRAY_BOUNDS_CHECK 71 namespace arrayManipulation
79 template<
typename INDEX_TYPE >
81 typename std::enable_if< std::is_signed< INDEX_TYPE >::value,
bool >::type
89 template<
typename INDEX_TYPE >
91 typename std::enable_if< !std::is_signed< INDEX_TYPE >::value,
bool >::type
102 template<
typename ITER >
104 typename std::iterator_traits< ITER >::difference_type
107 typename std::iterator_traits< ITER >::difference_type n = 0;
108 while( first != last )
124 template<
typename RandomAccessIterator >
126 typename std::iterator_traits< RandomAccessIterator >::difference_type
127 iterDistance( RandomAccessIterator first, RandomAccessIterator last, std::random_access_iterator_tag )
128 {
return last - first; }
137 template<
typename ITER >
139 typename std::iterator_traits< ITER >::difference_type
141 {
return iterDistance( first, last,
typename std::iterator_traits< ITER >::iterator_category() ); }
150 template<
typename T >
153 std::ptrdiff_t
const size )
157 if( !std::is_trivially_destructible< T >::value )
159 for( std::ptrdiff_t i = 0; i < size; ++i )
175 template<
typename ITER,
typename T >
179 T * LVARRAY_RESTRICT dst )
183 while( first != last )
185 new ( dst ) T( *first );
199 template<
typename T >
202 std::ptrdiff_t
const size,
203 T *
const LVARRAY_RESTRICT src )
209 for( std::ptrdiff_t i = 0; i < size; ++i )
211 new (dst + i) T( std::move( src[ i ] ) );
223 template<
typename T >
226 std::ptrdiff_t
const size,
227 std::ptrdiff_t
const amount )
236 for( std::ptrdiff_t j = 0; j < size; ++j )
238 new ( ptr + j - amount ) T( std::move( ptr[ j ] ) );
251 template<
typename T >
254 std::ptrdiff_t
const size,
255 std::ptrdiff_t
const amount )
264 for( std::ptrdiff_t j = size - 1; j >= 0; --j )
266 new ( ptr + amount + j ) T( std::move( ptr[ j ] ) );
281 template<
typename T,
typename ... ARGS >
283 void resize( T *
const LVARRAY_RESTRICT ptr,
284 std::ptrdiff_t
const size,
285 std::ptrdiff_t
const newSize,
293 destroy( ptr + newSize, size - newSize );
296 if(
sizeof ... ( ARGS ) == 0 && std::is_trivially_default_constructible< T >::value )
298 if( newSize - size > 0 )
300 std::size_t
const sizeDiff = integerConversion< std::size_t >( newSize - size );
301 std::memset( reinterpret_cast< void * >( ptr + size ), 0, ( sizeDiff ) *
sizeof( T ) );
307 for( std::size_t i = size; i < std::size_t( newSize ); ++i )
309 new ( ptr + i ) T( std::forward< ARGS >( args )... );
324 template<
typename T >
327 std::ptrdiff_t
const size,
328 std::ptrdiff_t
const index,
329 std::ptrdiff_t
const n )
340 for( std::ptrdiff_t i = size; i > index; --i )
342 std::ptrdiff_t
const curIndex = i - 1;
343 new ( ptr + curIndex + n ) T( std::move( ptr[ curIndex ] ) );
347 std::ptrdiff_t
const bounds = (index + n < size) ? index + n : size;
348 destroy( ptr + index, bounds - index );
361 template<
typename T >
364 std::ptrdiff_t
const size,
365 std::ptrdiff_t
const index,
366 std::ptrdiff_t
const n )
378 for( std::ptrdiff_t i = index; i < size; ++i )
380 ptr[i - n] = std::move( ptr[i] );
394 template<
typename T >
396 void erase( T *
const LVARRAY_RESTRICT ptr,
397 std::ptrdiff_t
const size,
398 std::ptrdiff_t
const index,
399 std::ptrdiff_t
const n=1 )
408 shiftDown( ptr, size, std::ptrdiff_t( index + n ), n );
423 template<
typename T,
typename ... ARGS >
426 std::ptrdiff_t
const size,
431 new ( ptr + size ) T( std::forward< ARGS >( args ) ... );
445 template<
typename T,
typename ITER >
447 std::ptrdiff_t
append( T *
const LVARRAY_RESTRICT ptr,
448 std::ptrdiff_t
const size,
455 std::ptrdiff_t i = 0;
456 while( first != last )
458 new( ptr + size + i ) T( *first );
476 template<
typename T,
typename ... ARGS >
479 std::ptrdiff_t
const size,
480 std::ptrdiff_t
const index,
488 shiftUp( ptr, size, index, std::ptrdiff_t( 1 ) );
489 new ( ptr + index ) T( std::forward< ARGS >( args ) ... );
503 template<
typename T,
typename ITERATOR >
505 void insert( T *
const LVARRAY_RESTRICT ptr,
506 std::ptrdiff_t
const size,
507 std::ptrdiff_t
const index,
509 std::ptrdiff_t
const n )
515 shiftUp( ptr, size, index, n );
517 for( std::ptrdiff_t i = 0; i < n; ++i )
519 new ( ptr + index + i ) T( *first );
531 template<
typename T >
534 std::ptrdiff_t
const size )
538 ptr[ size - 1 ].~T();
#define LVARRAY_ASSERT(EXP)
Assert EXP is true with no message.
Definition: Macros.hpp:184
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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.
Definition: arrayManipulation.hpp:447
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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.
Definition: arrayManipulation.hpp:201
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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.
Definition: arrayManipulation.hpp:425
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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.
Definition: arrayManipulation.hpp:505
Contains templates useful for type manipulation.
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void resize(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const newSize, ARGS &&... args)
Resize the give array.
Definition: arrayManipulation.hpp:283
Contains portable access to std::numeric_limits and functions for converting between integral types...
LVARRAY_HOST_DEVICE constexpr std::enable_if< std::is_signed< INDEX_TYPE >::value, bool >::type isPositive(INDEX_TYPE const i)
Definition: arrayManipulation.hpp:82
#define ARRAYMANIPULATION_CHECK_BOUNDS(index)
Check that index is a valid into into the array.
Definition: arrayManipulation.hpp:50
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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...
Definition: arrayManipulation.hpp:396
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void popBack(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size)
Destroy the value at the end of the array.
Definition: arrayManipulation.hpp:533
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void uninitializedCopy(ITER first, ITER const &last, T *LVARRAY_RESTRICT dst)
Copy construct values from the source to the destination.
Definition: arrayManipulation.hpp:177
The top level namespace.
Definition: Array.hpp:24
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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...
Definition: arrayManipulation.hpp:363
Contains a bunch of macro definitions.
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void destroy(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size)
Destory the values in the array.
Definition: arrayManipulation.hpp:152
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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.
Definition: arrayManipulation.hpp:326
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void uninitializedShiftDown(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const amount)
Shift values down into uninitialized memory.
Definition: arrayManipulation.hpp:225
#define DISABLE_HD_WARNING
Disable host device warnings.
Definition: Macros.hpp:561
DISABLE_HD_WARNING constexpr LVARRAY_HOST_DEVICE std::iterator_traits< ITER >::difference_type iterDistance(ITER first, ITER const last, std::input_iterator_tag)
Definition: arrayManipulation.hpp:105
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void uninitializedShiftUp(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const amount)
Shift values up into uninitialized memory.
Definition: arrayManipulation.hpp:253
#define ARRAYMANIPULATION_CHECK_INSERT_BOUNDS(index)
Check that index is a valid insertion position in the array.
Definition: arrayManipulation.hpp:57
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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.
Definition: arrayManipulation.hpp:478
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
Definition: Macros.hpp:549