@@ -148,8 +148,8 @@ namespace librapid {
148
148
LIBRAPID_NODISCARD LIBRAPID_ALWAYS_INLINE Pointer begin () noexcept ;
149
149
LIBRAPID_NODISCARD LIBRAPID_ALWAYS_INLINE Pointer end () noexcept ;
150
150
151
- LIBRAPID_NODISCARD LIBRAPID_ALWAYS_INLINE ConstIterator begin () const noexcept ;
152
- LIBRAPID_NODISCARD LIBRAPID_ALWAYS_INLINE ConstIterator end () const noexcept ;
151
+ LIBRAPID_NODISCARD LIBRAPID_ALWAYS_INLINE ConstPointer begin () const noexcept ;
152
+ LIBRAPID_NODISCARD LIBRAPID_ALWAYS_INLINE ConstPointer end () const noexcept ;
153
153
154
154
LIBRAPID_NODISCARD LIBRAPID_ALWAYS_INLINE ConstIterator cbegin () const noexcept ;
155
155
LIBRAPID_NODISCARD LIBRAPID_ALWAYS_INLINE ConstIterator cend () const noexcept ;
@@ -391,17 +391,22 @@ namespace librapid {
391
391
return ptr_;
392
392
}
393
393
394
- template <typename T>
395
- void fastCopy (T *__restrict dst, const T *__restrict src, size_t size) {
394
+ template <typename T, typename V >
395
+ void fastCopy (T *__restrict dst, const V *__restrict src, size_t size) {
396
396
LIBRAPID_ASSUME (size > 0 );
397
397
LIBRAPID_ASSUME (dst != nullptr );
398
398
LIBRAPID_ASSUME (src != nullptr );
399
399
400
- if (typetraits::TriviallyDefaultConstructible<T>::value) {
401
- // Use a slightly faster memcpy if the type is trivially default constructible
402
- std::uninitialized_copy (src, src + size, dst);
400
+ if constexpr (std::is_same_v<T, V>) {
401
+ if constexpr (typetraits::TriviallyDefaultConstructible<T>::value) {
402
+ // Use a slightly faster memcpy if the type is trivially default constructible
403
+ std::uninitialized_copy (src, src + size, dst);
404
+ } else {
405
+ // Otherwise, use the standard copy algorithm
406
+ std::copy (src, src + size, dst);
407
+ }
403
408
} else {
404
- // Otherwise, use the standard copy algorithm
409
+ // Cannot use memcpy if the types are different
405
410
std::copy (src, src + size, dst);
406
411
}
407
412
}
@@ -441,14 +446,14 @@ namespace librapid {
441
446
template <typename V>
442
447
Storage<T>::Storage(const std::initializer_list<V> &list) :
443
448
m_begin (nullptr ), m_size(0 ), m_ownsData(true ) {
444
- initData (list.begin (), list.end ());
449
+ initData (static_cast < const V *>( list.begin ()), static_cast < const V *>( list.end () ));
445
450
}
446
451
447
452
template <typename T>
448
453
template <typename V>
449
454
Storage<T>::Storage(const std::vector<V> &vector) :
450
455
m_begin (nullptr ), m_size(0 ), m_ownsData(true ) {
451
- initData (vector.begin () , vector.end ());
456
+ initData (static_cast < const V *>( vector.data ()) , vector.size ());
452
457
}
453
458
454
459
template <typename T>
@@ -620,12 +625,12 @@ namespace librapid {
620
625
}
621
626
622
627
template <typename T>
623
- auto Storage<T>::begin() const noexcept -> ConstIterator {
628
+ auto Storage<T>::begin() const noexcept -> ConstPointer {
624
629
return m_begin;
625
630
}
626
631
627
632
template <typename T>
628
- auto Storage<T>::end() const noexcept -> ConstIterator {
633
+ auto Storage<T>::end() const noexcept -> ConstPointer {
629
634
return m_begin + m_size;
630
635
}
631
636
0 commit comments