| 178 | |
| 179 | template <class T> |
| 180 | class TValue: public TMoveOnly { |
| 181 | class TConstructor { |
| 182 | public: |
| 183 | TConstructor() noexcept = default; |
| 184 | |
| 185 | virtual ~TConstructor() = default; |
| 186 | |
| 187 | virtual T* Construct(void* ptr) const = 0; |
| 188 | }; |
| 189 | |
| 190 | class TDefaultConstructor: public TConstructor { |
| 191 | public: |
| 192 | ~TDefaultConstructor() override = default; |
| 193 | |
| 194 | T* Construct(void* ptr) const override { |
| 195 | // memset(ptr, 0, sizeof(T)); |
| 196 | return ::new (ptr) T(); |
| 197 | } |
| 198 | }; |
| 199 | |
| 200 | template <class T1> |
| 201 | class TCopyConstructor: public TConstructor { |
| 202 | public: |
| 203 | inline TCopyConstructor(const T1& value) |
| 204 | : Value(value) |
| 205 | { |
| 206 | } |
| 207 | |
| 208 | ~TCopyConstructor() override = default; |
| 209 | |
| 210 | T* Construct(void* ptr) const override { |
| 211 | return ::new (ptr) T(Value); |
| 212 | } |
| 213 | |
| 214 | private: |
| 215 | T1 Value; |
| 216 | }; |
| 217 | |
| 218 | public: |
| 219 | inline TValue() |
| 220 | : Constructor_(new TDefaultConstructor()) |
| 221 | , Key_(Dtor) |
| 222 | { |
| 223 | } |
| 224 | |
| 225 | template <class T1> |
| 226 | inline TValue(const T1& value) |
| 227 | : Constructor_(new TCopyConstructor<T1>(value)) |
| 228 | , Key_(Dtor) |
| 229 | { |
| 230 | } |
| 231 | |
| 232 | template <class T1> |
| 233 | inline T& operator=(const T1& val) { |
| 234 | return Get() = val; |
| 235 | } |
| 236 | |
| 237 | inline operator const T&() const { |
no test coverage detected