aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/containers/stack_array/range_ops.h
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/containers/stack_array/range_ops.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/containers/stack_array/range_ops.h')
-rw-r--r--library/cpp/containers/stack_array/range_ops.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/library/cpp/containers/stack_array/range_ops.h b/library/cpp/containers/stack_array/range_ops.h
new file mode 100644
index 0000000000..1d40341aa1
--- /dev/null
+++ b/library/cpp/containers/stack_array/range_ops.h
@@ -0,0 +1,52 @@
+#pragma once
+
+#include <util/generic/typetraits.h>
+
+#include <new>
+
+namespace NRangeOps {
+ template <class T, bool isTrivial>
+ struct TRangeOpsBase {
+ static inline void DestroyRange(T* b, T* e) noexcept {
+ while (e > b) {
+ (--e)->~T();
+ }
+ }
+
+ static inline void InitializeRange(T* b, T* e) {
+ T* c = b;
+
+ try {
+ for (; c < e; ++c) {
+ new (c) T();
+ }
+ } catch (...) {
+ DestroyRange(b, c);
+
+ throw;
+ }
+ }
+ };
+
+ template <class T>
+ struct TRangeOpsBase<T, true> {
+ static inline void DestroyRange(T*, T*) noexcept {
+ }
+
+ static inline void InitializeRange(T*, T*) noexcept {
+ }
+ };
+
+ template <class T>
+ using TRangeOps = TRangeOpsBase<T, TTypeTraits<T>::IsPod>;
+
+ template <class T>
+ static inline void DestroyRange(T* b, T* e) noexcept {
+ TRangeOps<T>::DestroyRange(b, e);
+ }
+
+ template <class T>
+ static inline void InitializeRange(T* b, T* e) {
+ TRangeOps<T>::InitializeRange(b, e);
+ }
+}