SkTLazy constructors to require constructable.

The current SkTLazy copy and move constructors require copy or move
assignable instead of copy or move constructable. This prevents use with
classes with const members (since they cannot be assigned to after
construction). This change also brings SkTLazy more in line with
std::optional which will eventually take over most of what SkTLazy is used
for.

Change-Id: I7bad4edac6a8b3e8adeebc48400d7298a970ed31
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/204447
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
Ben Wagner 2019-03-28 12:02:20 -04:00 committed by Skia Commit-Bot
parent 4f98dbede6
commit 2f4e7b6840

View File

@ -21,8 +21,8 @@ template <typename T> class SkTLazy {
public:
SkTLazy() = default;
explicit SkTLazy(const T* src) : fPtr(src ? new (&fStorage) T(*src) : nullptr) {}
SkTLazy(const SkTLazy& that) { *this = that; }
SkTLazy(SkTLazy&& that) { *this = std::move(that); }
SkTLazy(const SkTLazy& that) : fPtr(that.fPtr ? new (&fStorage) T(*that.fPtr) : nullptr) {}
SkTLazy(SkTLazy&& that) : fPtr(that.fPtr ? new (&fStorage) T(std::move(*that.fPtr)) : nullptr){}
~SkTLazy() { this->reset(); }