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>
This commit is contained in:
Chris Blume 2017-04-25 17:33:13 -07:00 committed by Skia Commit-Bot
parent 101806f452
commit 2b6be207a1

View File

@ -442,11 +442,13 @@ be copied. It hides its copy-constructor and its assignment-operator.
*/
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++ */