MCPcopy Create free account
hub / github.com/apache/arrow / AlignedStorage

Class AlignedStorage

cpp/src/arrow/util/aligned_storage.h:31–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29
30template <typename T>
31class AlignedStorage {
32 public:
33 static constexpr bool can_memcpy = std::is_trivially_copyable<T>::value &&
34 std::is_trivially_default_constructible<T>::value;
35
36 constexpr T* get() noexcept {
37 return arrow::internal::launder(reinterpret_cast<T*>(&data_));
38 }
39
40 constexpr const T* get() const noexcept {
41 // Use fully qualified name to avoid ambiguities with MSVC (ARROW-14800)
42 return arrow::internal::launder(reinterpret_cast<const T*>(&data_));
43 }
44
45 void destroy() noexcept {
46 if (!std::is_trivially_destructible<T>::value) {
47 get()->~T();
48 }
49 }
50
51 template <typename... A>
52 void construct(A&&... args) noexcept {
53 new (&data_) T(std::forward<A>(args)...);
54 }
55
56 template <typename V>
57 void assign(V&& v) noexcept {
58 *get() = std::forward<V>(v);
59 }
60
61 void move_construct(AlignedStorage* other) noexcept {
62 new (&data_) T(std::move(*other->get()));
63 }
64
65 void move_assign(AlignedStorage* other) noexcept { *get() = std::move(*other->get()); }
66
67 template <bool CanMemcpy = can_memcpy>
68 static typename std::enable_if<CanMemcpy>::type move_construct_several(
69 AlignedStorage* ARROW_RESTRICT src, AlignedStorage* ARROW_RESTRICT dest, size_t n,
70 size_t memcpy_length) noexcept {
71 memcpy(dest->get(), src->get(), memcpy_length * sizeof(T));
72 }
73
74 template <bool CanMemcpy = can_memcpy>
75 static typename std::enable_if<CanMemcpy>::type
76 move_construct_several_and_destroy_source(AlignedStorage* ARROW_RESTRICT src,
77 AlignedStorage* ARROW_RESTRICT dest, size_t n,
78 size_t memcpy_length) noexcept {
79 memcpy(dest->get(), src->get(), memcpy_length * sizeof(T));
80 }
81
82 template <bool CanMemcpy = can_memcpy>
83 static typename std::enable_if<!CanMemcpy>::type move_construct_several(

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected