diff --git a/code/2/2.1.nullptr.cpp b/code/2/2.01.nullptr.cpp similarity index 100% rename from code/2/2.1.nullptr.cpp rename to code/2/2.01.nullptr.cpp diff --git a/code/2/2.2.constexpr.cpp b/code/2/2.02.constexpr.cpp similarity index 100% rename from code/2/2.2.constexpr.cpp rename to code/2/2.02.constexpr.cpp diff --git a/code/2/2.3.if.switch.cpp b/code/2/2.03.if.switch.cpp similarity index 100% rename from code/2/2.3.if.switch.cpp rename to code/2/2.03.if.switch.cpp diff --git a/code/2/2.4.initializer.list.cpp b/code/2/2.04.initializer.list.cpp similarity index 100% rename from code/2/2.4.initializer.list.cpp rename to code/2/2.04.initializer.list.cpp diff --git a/code/2/2.5.structured.binding.cpp b/code/2/2.05.structured.binding.cpp similarity index 100% rename from code/2/2.5.structured.binding.cpp rename to code/2/2.05.structured.binding.cpp diff --git a/code/2/2.6.auto.cpp b/code/2/2.06.auto.cpp similarity index 100% rename from code/2/2.6.auto.cpp rename to code/2/2.06.auto.cpp diff --git a/code/2/2.7.decltype.cpp b/code/2/2.07.decltype.cpp similarity index 100% rename from code/2/2.7.decltype.cpp rename to code/2/2.07.decltype.cpp diff --git a/code/2/2.8.tail.return.type.cpp b/code/2/2.08.tail.return.type.cpp similarity index 100% rename from code/2/2.8.tail.return.type.cpp rename to code/2/2.08.tail.return.type.cpp diff --git a/code/2/2.9.decltype.auto.cpp b/code/2/2.09.decltype.auto.cpp similarity index 100% rename from code/2/2.9.decltype.auto.cpp rename to code/2/2.09.decltype.auto.cpp diff --git a/code/2/2.4.cpp b/code/2/2.4.cpp deleted file mode 100644 index c9cd59d..0000000 --- a/code/2/2.4.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// -// 2.4.cpp -// c++1x tutorial -// -// created by changkun at changkun.de -// -// 区间迭代 - -#include -#include - -int main() { - int array[] = {1,2,3,4,5}; - for(auto &x : array) { - std::cout << x << std::endl; - } - - // 传统 C++ 写法 - std::vector arr(5, 100); - for(std::vector::iterator i = arr.begin(); i != arr.end(); ++i) { - std::cout << *i << std::endl; - } - - // C++11 写法 - // & 启用了引用, 如果没有则对 arr 中的元素只能读取不能修改 - for(auto &i : arr) { - std::cout << i << std::endl; - } - return 0; -} diff --git a/code/2/todo/2.6.autox.cpp b/code/2/todo/2.6.autox.cpp deleted file mode 100644 index e87c8fe..0000000 --- a/code/2/todo/2.6.autox.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// -// 2.3.cpp -// c++1x tutorial -// -// created by changkun at changkun.de -// -// auto/decltype/尾返回类型/返回类型推导 - - -#include - -// 传统 C++ -template -R add1(T x, U y) { - return x+y; -} - -// 尾返回类型 -template -auto add2(T x, U y) -> decltype(x+y) { - return x+y; -} - -// C++14 返回类型推导 -template -auto add3(T x, U y) { - return x+y; -} - -int main() { - auto i = 5; - - int arr[10] = {0}; - auto auto_arr = arr; // 正确,对整个类型进行推导 - // auto auto_arr2[10] = arr; // 错误, 无法推导数组元素类型 - - auto x = 1; - auto y = 2; - decltype(x+y) z1; - //auto z2; // 错误, 无法推导 - - - std::cout << add1(1,1) << std::endl; - std::cout << add1(1,1) << std::endl; - std::cout << add1(1,1) << std::endl; - - - return 0; -} diff --git a/code/2/2.6.cpp b/code/2/todo/2.6.cpp similarity index 100% rename from code/2/2.6.cpp rename to code/2/todo/2.6.cpp