Make SkNoncopyable movable
SkNoncopyable declares (but does not define) its copy constructor and
copy assignment operator. These are also private so the error for misuse
happens at compile-time instead of link-time.
However, this seems to be from before C++11.
Because other constructors were declared, the compiler does not generate
a move constructor or a move assignment operator. The result of this is
perfectly legal non-copying scenarios are also accidentally blocked. An
example of this is returning the non-copyable type. The object being
returned is a candidate for a move, since it is about to be destroyed.
And in C++17 copy elision is actually guaranteed.
Change-Id: Ia31be9091c644f31a45dd18216330a68be3cf456
Reviewed-on: https://skia-review.googlesource.com/14294
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index beb2be5..1dd672b 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -442,11 +442,13 @@
*/
class SK_API SkNoncopyable {
public:
- SkNoncopyable() {}
+ SkNoncopyable() = default;
-private:
- SkNoncopyable(const SkNoncopyable&);
- SkNoncopyable& operator=(const SkNoncopyable&);
+ SkNoncopyable(SkNoncopyable&&) = default;
+ SkNoncopyable& operator =(SkNoncopyable&&) = default;
+
+ SkNoncopyable(const SkNoncopyable&) = delete;
+ SkNoncopyable& operator=(const SkNoncopyable&) = delete;
};
#endif /* C++ */