[MSVC] error C2039: "uninitialized_move_n"

This commit is contained in:
mutouyun 2023-09-16 14:29:30 +08:00
parent 9bef0a7b18
commit 1c76f92687
3 changed files with 33 additions and 9 deletions

View File

@ -210,9 +210,9 @@
defined(__EXCEPTIONS) || defined(_CPPUNWIND) defined(__EXCEPTIONS) || defined(_CPPUNWIND)
# define LIBIMP_TRY try # define LIBIMP_TRY try
# define LIBIMP_CATCH(...) catch (__VA_ARGS__) # define LIBIMP_CATCH(...) catch (__VA_ARGS__)
# define LIBIMP_THROW($exception, $ret) throw $exception # define LIBIMP_THROW($exception, ...) throw $exception
#else #else
# define LIBIMP_TRY if (true) # define LIBIMP_TRY if (true)
# define LIBIMP_CATCH(...) else if (false) # define LIBIMP_CATCH(...) else if (false)
# define LIBIMP_THROW($exception, $ret) return $ret # define LIBIMP_THROW($exception, ...) return __VA_ARGS__
#endif #endif

View File

@ -121,4 +121,28 @@ ForwardIt uninitialized_default_construct_n(ForwardIt first, Size n) {
#endif #endif
} }
/**
* \brief Moves a number of objects to an uninitialized area of memory.
* \see https://en.cppreference.com/w/cpp/memory/uninitialized_move_n
*/
template <typename InputIt, typename Size, typename NoThrowForwardIt>
auto uninitialized_move_n(InputIt first, Size count, NoThrowForwardIt d_first)
-> std::pair<InputIt, NoThrowForwardIt> {
#if defined(LIBIMP_CPP_17)
return std::uninitialized_move_n(first, count, d_first);
#else
using Value = typename std::iterator_traits<NoThrowForwardIt>::value_type;
NoThrowForwardIt current = d_first;
LIBIMP_TRY {
for (; count > 0; ++first, (void) ++current, --count) {
::new (static_cast<void *>(std::addressof(*current))) Value(std::move(*first));
}
} LIBIMP_CATCH(...) {
destroy(d_first, current);
LIBIMP_THROW(, {first, d_first});
}
return {first, current};
#endif
}
LIBIMP_NAMESPACE_END_ LIBIMP_NAMESPACE_END_

View File

@ -219,7 +219,7 @@ struct holder_type : holder_type_base {
std::type_info const &type() const noexcept override { return typeid(Value); } std::type_info const &type() const noexcept override { return typeid(Value); }
void move(void *s, void *d, std::size_t n) const noexcept override { void move(void *s, void *d, std::size_t n) const noexcept override {
std::uninitialized_move_n(static_cast<Value *>(s), n, static_cast<Value *>(d)); ::LIBIMP::uninitialized_move_n(static_cast<Value *>(s), n, static_cast<Value *>(d));
} }
void copy(void const *s, void *d, std::size_t n) const noexcept(false) override { void copy(void const *s, void *d, std::size_t n) const noexcept(false) override {
std::uninitialized_copy_n(static_cast<Value const *>(s), n, static_cast<Value *>(d)); std::uninitialized_copy_n(static_cast<Value const *>(s), n, static_cast<Value *>(d));