| 25 | |
| 26 | template <typename T> |
| 27 | class Manual final { |
| 28 | public: |
| 29 | static_assert(!std::is_reference_v<T>, "T must not be a reference"); |
| 30 | static_assert(!std::is_array_v<T>, "T must not be an array"); |
| 31 | static_assert(!std::is_const_v<T>, "T must not be const qualified"); |
| 32 | static_assert(!std::is_volatile_v<T>, "T must not be volatile qualified"); |
| 33 | |
| 34 | using element_type = T; |
| 35 | |
| 36 | Manual() = default; |
| 37 | |
| 38 | Manual(const Manual&) = delete; |
| 39 | Manual(Manual&&) = delete; |
| 40 | |
| 41 | ~Manual() = default; |
| 42 | |
| 43 | Manual& operator=(const Manual&) = delete; |
| 44 | Manual& operator=(Manual&&) = delete; |
| 45 | |
| 46 | constexpr T* absl_nonnull get() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
| 47 | return std::launder(reinterpret_cast<T*>(&storage_[0])); |
| 48 | } |
| 49 | |
| 50 | constexpr const T* absl_nonnull get() const ABSL_ATTRIBUTE_LIFETIME_BOUND { |
| 51 | return std::launder(reinterpret_cast<const T*>(&storage_[0])); |
| 52 | } |
| 53 | |
| 54 | constexpr T& operator*() ABSL_ATTRIBUTE_LIFETIME_BOUND { return *get(); } |
| 55 | |
| 56 | constexpr const T& operator*() const ABSL_ATTRIBUTE_LIFETIME_BOUND { |
| 57 | return *get(); |
| 58 | } |
| 59 | |
| 60 | constexpr T* absl_nonnull operator->() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
| 61 | return get(); |
| 62 | } |
| 63 | |
| 64 | constexpr const T* absl_nonnull operator->() const |
| 65 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
| 66 | return get(); |
| 67 | } |
| 68 | |
| 69 | template <typename... Args> |
| 70 | T* absl_nonnull Construct(Args&&... args) ABSL_ATTRIBUTE_LIFETIME_BOUND { |
| 71 | return ::new (static_cast<void*>(&storage_[0])) |
| 72 | T(std::forward<Args>(args)...); |
| 73 | } |
| 74 | |
| 75 | T* absl_nonnull DefaultConstruct() { |
| 76 | return ::new (static_cast<void*>(&storage_[0])) T; |
| 77 | } |
| 78 | |
| 79 | T* absl_nonnull ValueConstruct() { |
| 80 | return ::new (static_cast<void*>(&storage_[0])) T(); |
| 81 | } |
| 82 | |
| 83 | void Destruct() { get()->~T(); } |
| 84 | |