23 static constexpr size_t capacity = S;
32 if constexpr (should_call_destructor<T>()) {
34 std::destroy_at(this->operator->());
45 std::enable_if_t<std::is_base_of_v<base_type, O>,
polymorphic_value> &operator=(O
const &other) {
46 static_assert(
sizeof(O) <= capacity,
"Assignment of a type larger than capacity of polymorphic_value");
50 if constexpr (should_call_destructor<T>()) {
57 std::enable_if_t<std::is_base_of_v<base_type, O>,
polymorphic_value> &operator=(O &&other) {
58 static_assert(
sizeof(O) <= capacity,
"Assignment of a type larger than capacity of polymorphic_value");
60 new(data()) O(std::forward<O>(other));
62 if constexpr (should_call_destructor<T>()) {
68 template<
typename O,
typename... Args>
69 std::enable_if_t<std::is_base_of_v<base_type, O>,
void> emplace(Args &&... args) {
70 static_assert(
sizeof(O) <= capacity,
"Assignment of a type larger than capacity of polymorphic_value");
72 new(data()) O(std::forward<Args>(args)...);
74 if constexpr (should_call_destructor<T>()) {
79 void reset()
noexcept {
80 if constexpr (should_call_destructor<T>()) {
82 std::destroy_at(this->operator->());
88 void *data()
noexcept {
89 return reinterpret_cast<void *
>(_data.
data());
92 void const *data()
const noexcept {
93 return reinterpret_cast<void const *
>(_data.
data());
96 T
const &operator*()
const noexcept {
97 if constexpr (should_call_destructor<T>()) {
100 return *
reinterpret_cast<T
const *
>(data());
103 T &operator*()
noexcept {
104 if constexpr (should_call_destructor<T>()) {
105 tt_assert(has_value);
107 return *
reinterpret_cast<T *
>(data());
110 T
const *operator->()
const noexcept {
111 if constexpr (should_call_destructor<T>()) {
112 tt_assert(has_value);
114 return reinterpret_cast<T
const *
>(data());
117 T *operator->()
noexcept {
118 if constexpr (should_call_destructor<T>()) {
119 tt_assert(has_value);
121 return reinterpret_cast<T *
>(data());