aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-07-01 12:33:39 -0700
committerChris Robinson <[email protected]>2019-07-01 12:33:39 -0700
commitc9ffa9d466f5d0a24c9f51f430b19410abdf868f (patch)
tree7bd16375045dbe683e31ab27b0425bae54cc58b8 /common
parente9b41d9b90407285dd5fc74165051af907608d7e (diff)
Add C++17-like uninitialized_move methods
Diffstat (limited to 'common')
-rw-r--r--common/almalloc.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/common/almalloc.h b/common/almalloc.h
index 23f9edce..801df1d8 100644
--- a/common/almalloc.h
+++ b/common/almalloc.h
@@ -144,6 +144,49 @@ inline T uninitialized_default_construct_n(T first, N count)
}
+template<typename T0, typename T1>
+inline T1 uninitialized_move(T0 first, const T0 last, const T1 output)
+{
+ using ValueT = typename std::iterator_traits<T1>::value_type;
+ T1 current{output};
+ try {
+ while(first != last)
+ {
+ ::new (static_cast<void*>(std::addressof(*current))) ValueT{std::move(*first)};
+ ++current;
+ ++first;
+ }
+ }
+ catch(...) {
+ destroy(output, current);
+ throw;
+ }
+ return current;
+}
+
+template<typename T0, typename N, typename T1, REQUIRES(std::is_integral<N>::value)>
+inline T1 uninitialized_move_n(T0 first, N count, const T1 output)
+{
+ using ValueT = typename std::iterator_traits<T1>::value_type;
+ T1 current{output};
+ if(count != 0)
+ {
+ try {
+ do {
+ ::new (static_cast<void*>(std::addressof(*current))) ValueT{std::move(*first)};
+ ++current;
+ ++first;
+ } while(--count);
+ }
+ catch(...) {
+ destroy(output, current);
+ throw;
+ }
+ }
+ return current;
+}
+
+
/* std::make_unique was added with C++14, so until we rely on that, make our
* own version.
*/