1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
| auto and decltype { int x = 8; int y = 9; auto z = x + y; decltype(z) a = x + y; template<typename A, typename B> decltype(a+b) Add(A& a, B& b) { return a + b; } }
trailing return type { template<typename T, typename Y> auto add(T v1, Y v2) -> decltype(v1 + v2) { return v1 + v2; } }
override and final { struct Base { virtual void func(); }; struct A:Base { void func() final; }; struct B:A { void func() override; }; }
lvalue and rvalue { int x = 8; std::cout<<"x: "<<x<<std::endl; { 1. 左值可变,右值不可变(const type) 2. 左值生存周期可以很长,右值只用一次 3. 左值储存在内存区,右值没有固定地址,用完即释放 4. 左值可以取地址,右值不可以 } 使用: int a = 8; int &x = a; int &&x = a; int &&x = 8;
const int &x = 8; 有什么用: struct A{ A(int &&x){ cout<<"x: "<<x<<endl; } }; A a(1); }
default and delete { class A { A() = default; ~A() = default; A(const A&) = default; A(A&&) = default; A& operator=(const A&) = default; A& operator=(A&&) = default; }; void func() = delete; class B { B& operator=(const B&) = delete; } }
move constructors { struct B; B b; B a = std::move(b); }
scoped enums { enum class : int{ a = 0, b, c, d }; }
constexpr { constexpr int x = 8; }
delegating and inherited constructors { struct A { A(const in& x, const int& y) :m_x(x),m_y(y) {} A(const int& y) :A(2,y) {} private: int m_x; int m_y; }; struct B : A&{ B(const in& x, const int& y) :A(x, y) {} }; }
type aliases { using Degree = Angle<is_degree>; using Radian = Angle<is_radian>; }
variadic templates { template<class... Types> struct Tuple {}; Tuple<> t0; Tuple<int> t1; Tuple<int, float> t2; Tuple<0> t3; template<class... Types> void f(Types... args); f(); f(1); f(2, 1.0); }
lambda { auto a = []()->type{}; }
range-for { int a[4] = {1, 2, 3, 4}; for(int i : a) { cout<<" "<<i; } cout<<endl; }
static_assert { static_assert(true, "success pass!"); }
alignof { std::size_t alignof(type) }
|