blob: 3130e6f95bd1edf99cdccd74b600e921abe68ab9 [file] [log] [blame]
mtklein1138be42016-01-24 19:49:24 -08001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#include "Test.h"
8#include "SkTemplates.h"
9#include <utility>
10
11namespace {
12class Moveable {
13public:
14 Moveable() {}
15 Moveable(Moveable&&) {}
16 Moveable& operator=(Moveable&&) { return *this; }
17private:
18 Moveable(const Moveable&);
19 Moveable& operator=(const Moveable&);
20};
21template <typename T> void deleter(T*) { }
22template <typename T> struct Deleter {
23 void operator()(T* t) { delete static_cast<const Moveable*>(t); }
24};
25} // namespace
26
27DEF_TEST(CPlusPlusEleven_RvalueAndMove, r) {
28 Moveable src1; Moveable dst1(std::move(src1));
29 Moveable src2, dst2; dst2 = std::move(src2);
30}
halcanarya0af7712016-05-23 09:11:58 -070031
32DEF_TEST(CPlusPlusEleven_constexpr, r) {
33 static constexpr int x = Sk32ToBool(50);
34 REPORTER_ASSERT(r, x == 1);
35 static constexpr int y = SkTPin<int>(100, 0, 10);
36 REPORTER_ASSERT(r, y == 10);
37}
halcanarydabd4f02016-08-03 11:16:56 -070038
39namespace {
40struct MoveableCopyable {
41 bool fCopied;
42 MoveableCopyable() : fCopied(false) {}
43 MoveableCopyable(const MoveableCopyable &o) : fCopied(true) {}
44 MoveableCopyable(MoveableCopyable &&o) : fCopied(o.fCopied) {}
45};
46struct TestClass {
47 MoveableCopyable fFoo;
48};
49} // namespace
50
51DEF_TEST(CPlusPlusEleven_default_move, r) {
52 TestClass a;
53 TestClass b(a);
54 TestClass c(std::move(a));
55 REPORTER_ASSERT(r, b.fFoo.fCopied);
56 REPORTER_ASSERT(r, !c.fFoo.fCopied);
57}