├── Any.hpp ├── Aspect.hpp ├── Bind.hpp ├── DllParser.hpp ├── Format.hpp ├── Ioc.hpp ├── Lazy.hpp ├── LinqCpp.hpp ├── MessageBus.hpp ├── Nan-boxing.hpp ├── NonCopyable.hpp ├── Optional.hpp ├── README.md ├── Range.hpp ├── ScopeGuard.hpp ├── SharedptrUtil.hpp ├── SyncQueue.hpp ├── ThreadPool.hpp ├── Timer.hpp ├── Variant.hpp ├── cache.hpp ├── cpp11book ├── rest_code.txt ├── 第一章 │ ├── 1-1 │ │ ├── 1-1.sln │ │ ├── 1-1.v12.suo │ │ └── 1-1 │ │ │ ├── 1-1.vcxproj │ │ │ ├── 1-1.vcxproj.filters │ │ │ └── Test.cpp │ ├── 1-10 │ │ ├── 1-10.sln │ │ ├── 1-10.v12.suo │ │ └── 1-10 │ │ │ ├── 1-10.vcxproj │ │ │ ├── 1-10.vcxproj.filters │ │ │ └── Test.cpp │ ├── 1-11~1-15 │ │ ├── 1-11~1-15.sln │ │ ├── 1-11~1-15.v12.suo │ │ └── 1-11~1-15 │ │ │ ├── 1-11~1-15.vcxproj │ │ │ ├── 1-11~1-15.vcxproj.filters │ │ │ ├── Range.hpp │ │ │ └── Test.cpp │ ├── 1-16 │ │ ├── 1-16.sln │ │ ├── 1-16.v12.suo │ │ └── 1-16 │ │ │ ├── 1-16.vcxproj │ │ │ ├── 1-16.vcxproj.filters │ │ │ └── Test.cpp │ ├── 1-17 │ │ ├── 1-17.sln │ │ ├── 1-17.v12.suo │ │ └── 1-17 │ │ │ ├── 1-17.vcxproj │ │ │ ├── 1-17.vcxproj.filters │ │ │ └── Test.cpp │ ├── 1-19 │ │ ├── 1-19.sln │ │ ├── 1-19.v12.suo │ │ └── 1-19 │ │ │ ├── 1-19.vcxproj │ │ │ ├── 1-19.vcxproj.filters │ │ │ └── Test.cpp │ ├── 1-2 │ │ ├── 1-2.sln │ │ ├── 1-2.v12.suo │ │ └── 1-2 │ │ │ ├── 1-2.vcxproj │ │ │ ├── 1-2.vcxproj.filters │ │ │ └── Test2.cpp │ ├── 1-20 │ │ ├── 1-20.sln │ │ ├── 1-20.v12.suo │ │ └── 1-20 │ │ │ ├── 1-20.vcxproj │ │ │ ├── 1-20.vcxproj.filters │ │ │ └── Test.cpp │ ├── 1-21 │ │ ├── 1-21.sln │ │ ├── 1-21.v12.suo │ │ └── 1-21 │ │ │ ├── 1-21.vcxproj │ │ │ ├── 1-21.vcxproj.filters │ │ │ └── Test.cpp │ ├── 1-22 │ │ ├── 1-22.sln │ │ ├── 1-22.v12.suo │ │ └── 1-22 │ │ │ ├── 1-22.vcxproj │ │ │ ├── 1-22.vcxproj.filters │ │ │ └── test.cpp │ ├── 1-23 │ │ ├── 1-23.sln │ │ ├── 1-23.v12.suo │ │ └── 1-23 │ │ │ ├── 1-23.vcxproj │ │ │ ├── 1-23.vcxproj.filters │ │ │ └── Test.cpp │ ├── 1-24 │ │ ├── 1-24.sln │ │ ├── 1-24.v12.suo │ │ └── 1-24 │ │ │ ├── 1-24.vcxproj │ │ │ ├── 1-24.vcxproj.filters │ │ │ └── Test.cpp │ ├── 1-3 │ │ ├── 1-3.sln │ │ ├── 1-3.v12.suo │ │ └── 1-3 │ │ │ ├── 1-3.vcxproj │ │ │ ├── 1-3.vcxproj.filters │ │ │ └── Test.cpp │ ├── 1-4 │ │ ├── 1-4.sln │ │ ├── 1-4.v12.suo │ │ └── 1-4 │ │ │ ├── 1-4.vcxproj │ │ │ ├── 1-4.vcxproj.filters │ │ │ └── Test.cpp │ ├── 1-5 │ │ ├── 1-5.sln │ │ ├── 1-5.v12.suo │ │ └── 1-5 │ │ │ ├── 1-5.vcxproj │ │ │ ├── 1-5.vcxproj.filters │ │ │ └── Test.cpp │ ├── 1-7 │ │ ├── 1-7.sln │ │ ├── 1-7.v12.suo │ │ └── 1-7 │ │ │ ├── 1-7.vcxproj │ │ │ ├── 1-7.vcxproj.filters │ │ │ └── Test.cpp │ ├── 1-8 │ │ ├── 1-8.sln │ │ ├── 1-8.v12.suo │ │ └── 1-8 │ │ │ ├── 1-8.vcxproj │ │ │ ├── 1-8.vcxproj.filters │ │ │ └── Test.cpp │ ├── 1-9 │ │ ├── 1-9.sln │ │ ├── 1-9.v12.suo │ │ └── 1-9 │ │ │ ├── 1-9.vcxproj │ │ │ ├── 1-9.vcxproj.filters │ │ │ └── Test.cpp │ └── VC清理助手.bat ├── 第三章 │ ├── 3-1 │ │ ├── 3-1.sln │ │ ├── 3-1.v12.suo │ │ └── 3-1 │ │ │ ├── 3-1.vcxproj │ │ │ ├── 3-1.vcxproj.filters │ │ │ └── Test.cpp │ ├── 3-10 │ │ ├── 3-10.sln │ │ ├── 3-10.v12.suo │ │ └── 3-10 │ │ │ ├── 3-10.vcxproj │ │ │ ├── 3-10.vcxproj.filters │ │ │ ├── DllParser.hpp │ │ │ ├── MyDLL.dll │ │ │ └── Test.cpp │ ├── 3-12 │ │ ├── 3-12.sln │ │ ├── 3-12.v12.suo │ │ └── 3-12 │ │ │ ├── 3-12.vcxproj │ │ │ ├── 3-12.vcxproj.filters │ │ │ └── Test.cpp │ ├── 3-13 │ │ ├── 3-13.sln │ │ ├── 3-13.v12.suo │ │ └── 3-13 │ │ │ ├── 3-13.vcxproj │ │ │ ├── 3-13.vcxproj.filters │ │ │ ├── Any.hpp │ │ │ └── 源.cpp │ ├── 3-14 │ │ ├── 3-14.sln │ │ ├── 3-14.v12.suo │ │ └── 3-14 │ │ │ ├── 3-14.vcxproj │ │ │ ├── 3-14.vcxproj.filters │ │ │ └── Test.cpp │ ├── 3-15 │ │ ├── 3-15.sln │ │ ├── 3-15.v12.suo │ │ └── 3-15 │ │ │ ├── 3-15.vcxproj │ │ │ ├── 3-15.vcxproj.filters │ │ │ ├── Test.cpp │ │ │ └── Variant.hpp │ ├── 3-16 │ │ ├── 3-16.sln │ │ ├── 3-16.v12.suo │ │ └── 3-16 │ │ │ ├── 3-16.vcxproj │ │ │ ├── 3-16.vcxproj.filters │ │ │ ├── ScopeGuard.hpp │ │ │ └── Test.cpp │ ├── 3-17 │ │ ├── 3-17.sln │ │ ├── 3-17.v12.suo │ │ └── 3-17 │ │ │ ├── 3-17.vcxproj │ │ │ ├── 3-17.vcxproj.filters │ │ │ └── Test.cpp │ ├── 3-18 │ │ ├── 3-18.sln │ │ ├── 3-18.v12.suo │ │ └── 3-18 │ │ │ ├── 3-18.vcxproj │ │ │ ├── 3-18.vcxproj.filters │ │ │ └── Test.cpp │ ├── 3-19 │ │ ├── 3-19.sln │ │ ├── 3-19.v11.suo │ │ ├── 3-19.v12.suo │ │ └── 3-19 │ │ │ ├── 3-19.vcxproj │ │ │ ├── 3-19.vcxproj.filters │ │ │ └── Test.cpp │ ├── 3-2 │ │ ├── 3-2.sln │ │ ├── 3-2.v12.suo │ │ └── 3-2 │ │ │ ├── 3-2.vcxproj │ │ │ ├── 3-2.vcxproj.filters │ │ │ └── Test.cpp │ ├── 3-20 │ │ ├── 3-20.sln │ │ ├── 3-20.v12.suo │ │ └── 3-20 │ │ │ ├── 3-20.vcxproj │ │ │ ├── 3-20.vcxproj.filters │ │ │ └── Test.cpp │ ├── 3-21 │ │ ├── 3-21.sln │ │ ├── 3-21.v12.suo │ │ └── 3-21 │ │ │ ├── 3-21.vcxproj │ │ │ ├── 3-21.vcxproj.filters │ │ │ └── Test.cpp │ ├── 3-22 │ │ ├── 3-22.sln │ │ ├── 3-22.v12.suo │ │ └── 3-22 │ │ │ ├── 3-22.vcxproj │ │ │ ├── 3-22.vcxproj.filters │ │ │ ├── Test.cpp │ │ │ ├── TpForeach.hpp │ │ │ └── TpIndexs.hpp │ ├── 3-23 │ │ ├── 3-23.sln │ │ ├── 3-23.v12.suo │ │ └── 3-23 │ │ │ ├── 3-23.vcxproj │ │ │ ├── 3-23.vcxproj.filters │ │ │ └── Test.cpp │ ├── 3-24 │ │ ├── 3-24.sln │ │ ├── 3-24.v12.suo │ │ └── 3-24 │ │ │ ├── 3-24.vcxproj │ │ │ ├── 3-24.vcxproj.filters │ │ │ └── Test.cpp │ ├── 3-25 │ │ ├── 3-25.sln │ │ ├── 3-25.v12.suo │ │ └── 3-25 │ │ │ ├── 3-25.vcxproj │ │ │ ├── 3-25.vcxproj.filters │ │ │ ├── Test.cpp │ │ │ └── TpZip.hpp │ ├── 3-3 │ │ ├── 3-3.sln │ │ ├── 3-3.v12.suo │ │ └── 3-3 │ │ │ ├── 3-3.vcxproj │ │ │ ├── 3-3.vcxproj.filters │ │ │ └── Test.cpp │ ├── 3-4 │ │ ├── 3-4.sln │ │ ├── 3-4.v12.suo │ │ └── 3-4 │ │ │ ├── 3-4.vcxproj │ │ │ ├── 3-4.vcxproj.filters │ │ │ └── Test.cpp │ ├── 3-5 │ │ ├── 3-5.sln │ │ ├── 3-5.v12.suo │ │ └── 3-5 │ │ │ ├── 3-5.vcxproj │ │ │ ├── 3-5.vcxproj.filters │ │ │ ├── Test.cpp │ │ │ └── optional.hpp │ ├── 3-7~3-8 │ │ ├── 3-7~3-8.sln │ │ ├── 3-7~3-8.v12.suo │ │ └── 3-7~3-8 │ │ │ ├── 3-7~3-8.vcxproj │ │ │ ├── 3-7~3-8.vcxproj.filters │ │ │ ├── Lazy.hpp │ │ │ └── Test.cpp │ └── 3-9 │ │ ├── 3-9.sln │ │ ├── 3-9.v12.suo │ │ └── 3-9 │ │ ├── 3-9.vcxproj │ │ ├── 3-9.vcxproj.filters │ │ ├── MyDLL.dll │ │ ├── MyDLL.h │ │ ├── MyDLL.lib │ │ └── Test.cpp ├── 第二章 │ ├── 2-1 │ │ ├── 2-1.sln │ │ ├── 2-1.v12.suo │ │ └── 2-1 │ │ │ ├── 2-1.vcxproj │ │ │ ├── 2-1.vcxproj.filters │ │ │ └── Test.cpp │ ├── 2-2 │ │ ├── 2-2.sln │ │ ├── 2-2.v12.suo │ │ └── 2-2 │ │ │ ├── 2-2.vcxproj │ │ │ ├── 2-2.vcxproj.filters │ │ │ └── Test.cpp │ ├── 2-3 │ │ ├── 2-3.sln │ │ ├── 2-3.v12.suo │ │ └── 2-3 │ │ │ ├── 2-3.vcxproj │ │ │ ├── 2-3.vcxproj.filters │ │ │ └── Test.cpp │ ├── 2-4 │ │ ├── 2-4.sln │ │ ├── 2-4.v12.suo │ │ └── 2-4 │ │ │ ├── 2-4.vcxproj │ │ │ ├── 2-4.vcxproj.filters │ │ │ └── Test.cpp │ ├── 2-5 │ │ ├── 2-5.sln │ │ ├── 2-5.v12.suo │ │ └── 2-5 │ │ │ ├── 2-5.vcxproj │ │ │ ├── 2-5.vcxproj.filters │ │ │ └── Test.cpp │ ├── 2-6 │ │ ├── 2-6.sln │ │ ├── 2-6.v12.suo │ │ └── 2-6 │ │ │ ├── 2-6.vcxproj │ │ │ ├── 2-6.vcxproj.filters │ │ │ └── Test.cpp │ └── VC清理助手.bat ├── 第五章 │ ├── 5-1 │ │ ├── 5-1.sln │ │ ├── 5-1.v12.suo │ │ └── 5-1 │ │ │ ├── 5-1.vcxproj │ │ │ ├── 5-1.vcxproj.filters │ │ │ └── Test.cpp │ ├── 5-10 │ │ ├── 5-10.sln │ │ ├── 5-10.v12.suo │ │ └── 5-10 │ │ │ ├── 5-10.vcxproj │ │ │ ├── 5-10.vcxproj.filters │ │ │ └── Test.cpp │ ├── 5-2 │ │ ├── 5-2.sln │ │ ├── 5-2.v12.suo │ │ └── 5-2 │ │ │ ├── 5-2.vcxproj │ │ │ ├── 5-2.vcxproj.filters │ │ │ └── Test.cpp │ ├── 5-3 │ │ ├── 5-3.sln │ │ ├── 5-3.v12.suo │ │ └── 5-3 │ │ │ ├── 5-3.vcxproj │ │ │ ├── 5-3.vcxproj.filters │ │ │ └── Test.cpp │ ├── 5-4 │ │ ├── 5-4.sln │ │ ├── 5-4.v12.suo │ │ └── 5-4 │ │ │ ├── 5-4.vcxproj │ │ │ ├── 5-4.vcxproj.filters │ │ │ └── Test.cpp │ ├── 5-5 │ │ ├── 5-5.sln │ │ ├── 5-5.v12.suo │ │ └── 5-5 │ │ │ ├── 5-5.vcxproj │ │ │ ├── 5-5.vcxproj.filters │ │ │ ├── SyncQueue.hpp │ │ │ └── Test.cpp │ ├── 5-6 │ │ ├── 5-6.sln │ │ ├── 5-6.v12.suo │ │ └── 5-6 │ │ │ ├── 5-6.vcxproj │ │ │ ├── 5-6.vcxproj.filters │ │ │ ├── SimpleSyncQueue.hpp │ │ │ └── Test.cpp │ ├── 5-7 │ │ ├── 5-7.sln │ │ ├── 5-7.v12.suo │ │ └── 5-7 │ │ │ ├── 5-7.vcxproj │ │ │ ├── 5-7.vcxproj.filters │ │ │ └── Test.cpp │ ├── 5-8 │ │ ├── 5-8.sln │ │ ├── 5-8.v12.suo │ │ └── 5-8 │ │ │ ├── 5-8.vcxproj │ │ │ ├── 5-8.vcxproj.filters │ │ │ └── Test.cpp │ └── 5-9 │ │ ├── 5-9.sln │ │ ├── 5-9.v12.suo │ │ └── 5-9 │ │ ├── 5-9.vcxproj │ │ ├── 5-9.vcxproj.filters │ │ └── Test.cpp ├── 第六章 │ ├── 6-1 │ │ ├── 6-1.sln │ │ ├── 6-1.v12.suo │ │ └── 6-1 │ │ │ ├── 6-1.vcxproj │ │ │ ├── 6-1.vcxproj.filters │ │ │ ├── Test.cpp │ │ │ └── Timer.hpp │ ├── 6-2 │ │ ├── 6-2.sln │ │ ├── 6-2.v12.suo │ │ └── 6-2 │ │ │ ├── 6-2.vcxproj │ │ │ ├── 6-2.vcxproj.filters │ │ │ └── Test.cpp │ ├── 6-3 │ │ ├── 6-3.sln │ │ ├── 6-3.v12.suo │ │ └── 6-3 │ │ │ ├── 6-3.vcxproj │ │ │ ├── 6-3.vcxproj.filters │ │ │ └── Test.cpp │ └── VC清理助手.bat └── 第四章 │ └── 4-1 │ ├── 4-1.sln │ ├── 4-1.v12.suo │ └── 4-1 │ ├── 4-1.vcxproj │ ├── 4-1.vcxproj.filters │ └── Test.cpp ├── fun_test.hpp ├── function_message_bus.hpp ├── function_traits.hpp ├── lexical_cast.hpp ├── modern_functor.hpp ├── modern_messagebus.hpp ├── object_pool └── SimpleObjectPool.hpp ├── pattern ├── Command.hpp ├── ObjectPool.hpp ├── Observer.hpp ├── Singleton.hpp └── Visitor.hpp ├── pod_reflection.hpp ├── reflection.hpp ├── router.hpp ├── self-register-factory ├── Message.hpp ├── Message1.hpp ├── MessageFactory.hpp ├── MessageFatory1.hpp └── main.cpp ├── tuple ├── TpApply.hpp ├── TpForeach.hpp ├── TpIndexs.hpp ├── TpPrint.hpp └── TpZip.hpp ├── type_name.hpp ├── variadic2tuple.hpp └── worksteal ├── main.cpp ├── sync_deque.hpp ├── thread_pool.hpp └── worker.hpp /DllParser.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | class DllParser 9 | { 10 | public: 11 | 12 | DllParser():m_hMod(nullptr) 13 | { 14 | } 15 | 16 | ~DllParser() 17 | { 18 | UnLoad(); 19 | } 20 | 21 | bool Load(const string& dllPath) 22 | { 23 | m_hMod = LoadLibraryA(dllPath.data()); 24 | if (nullptr == m_hMod) 25 | { 26 | printf("LoadLibrary failed\n"); 27 | return false; 28 | } 29 | 30 | return true; 31 | } 32 | 33 | bool UnLoad() 34 | { 35 | if (m_hMod == nullptr) 36 | return true; 37 | 38 | auto b = FreeLibrary(m_hMod); 39 | if (!b) 40 | return false; 41 | 42 | m_hMod = nullptr; 43 | return true; 44 | } 45 | 46 | template 47 | std::function GetFunction(const string& funcName) 48 | { 49 | auto it = m_map.find(funcName); 50 | if (it == m_map.end()) 51 | { 52 | auto addr = GetProcAddress(m_hMod, funcName.c_str()); 53 | if (!addr) 54 | return nullptr; 55 | m_map.insert(std::make_pair(funcName, addr)); 56 | it = m_map.find(funcName); 57 | } 58 | 59 | return std::function((T*) (it->second)); 60 | } 61 | 62 | template 63 | typename std::result_of(Args...)>::type ExcecuteFunc(const string& funcName, Args&&... args) 64 | { 65 | auto f = GetFunction(funcName); 66 | if (f == nullptr) 67 | { 68 | string s = "can not find this function " + funcName; 69 | throw std::exception(s.c_str()); 70 | } 71 | 72 | return f(std::forward(args)...); 73 | } 74 | 75 | private: 76 | HMODULE m_hMod; 77 | std::map m_map; 78 | }; 79 | -------------------------------------------------------------------------------- /Lazy.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | template 4 | struct Lazy 5 | { 6 | template 7 | Lazy(Func& f, Args && ... args) 8 | { 9 | m_func = [&f, &args...]{return f(args...); }; 10 | } 11 | 12 | T& Value() 13 | { 14 | if (!m_value.IsInit()) 15 | { 16 | m_value = m_func(); 17 | } 18 | 19 | return *m_value; 20 | } 21 | 22 | bool IsValueCreated() const 23 | { 24 | return m_value.IsInit(); 25 | } 26 | 27 | private: 28 | std::function m_func; 29 | Optional m_value; 30 | }; 31 | 32 | template 33 | Lazy::type> 34 | lazy(Func && fun, Args && ... args) 35 | { 36 | return Lazy::type>(std::forward(fun), std::forward(args)...); 37 | } 38 | -------------------------------------------------------------------------------- /NonCopyable.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | class NonCopyable 3 | { 4 | public: 5 | NonCopyable(const NonCopyable&) = delete; // deleted 6 | NonCopyable& operator = (const NonCopyable&) = delete; // deleted 7 | NonCopyable() = default; // available 8 | }; 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cosmos 2 | ====== 3 | 桃李不言,下自成蹊。 4 | 5 | 尽自己一份力,让c++的世界变得更美好! 6 | 7 | C++开源社区:http://purecpp.cn/ 8 | -------------------------------------------------------------------------------- /ScopeGuard.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | template 3 | class ScopeGuard 4 | { 5 | public: 6 | explicit ScopeGuard(F && f) : m_func(std::move(f)), m_dismiss(false){} 7 | explicit ScopeGuard(const F& f) : m_func(f), m_dismiss(false){} 8 | 9 | ~ScopeGuard() 10 | { 11 | if (!m_dismiss&&m_func != nullptr) 12 | m_func(); 13 | } 14 | 15 | ScopeGuard(ScopeGuard && rhs) : m_func(std::move(rhs.m_func)), m_dismiss(rhs.m_dismiss) 16 | { 17 | rhs.Dismiss(); 18 | } 19 | 20 | void Dismiss() 21 | { 22 | m_dismiss = true; 23 | } 24 | 25 | private: 26 | F m_func; 27 | bool m_dismiss; 28 | 29 | ScopeGuard(); 30 | ScopeGuard(const ScopeGuard&); 31 | ScopeGuard&operator=(const ScopeGuard&); 32 | }; 33 | 34 | template ScopeGuard::type> MakeGuard(F && f) 35 | { 36 | return ScopeGuard::type>(std::forward(f)); 37 | } 38 | -------------------------------------------------------------------------------- /SharedptrUtil.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | using namespace std; 4 | 5 | //通过shared_ptr创建数组 6 | template 7 | shared_ptr make_shared_array(size_t size) 8 | { 9 | return shared_ptr(new T[size], default_delete()); 10 | } 11 | 12 | //make_unique的实现 13 | //支持普通指针 14 | template inline 15 | typename enable_if::value, unique_ptr >::type make_unique(Args&&... args) 16 | { 17 | return unique_ptr(new T(std::forward(args)...)); 18 | } 19 | 20 | //支持动态数组 21 | template inline 22 | typename enable_if::value && extent::value==0, unique_ptr >::type 23 | 24 | make_unique(size_t size) 25 | { 26 | typedef typename remove_extent::type U; 27 | return unique_ptr(new U[size]()); 28 | } 29 | 30 | //过滤掉定长数组的情况 31 | template 32 | typename enable_if::value != 0, void>::type make_unique(Args&&...) = delete; 33 | 34 | //------shared_ptr异常安全地管理第三方内存 35 | #define GUARD(P) std::shared_ptr p##p(p, [](void*p){ GetHandle()->Release(p);}); 36 | 37 | void* p = GetHandle()->Create(); 38 | GUARD(p); //安全 39 | 40 | //------unique_ptr异常安全地管理第三方内存 41 | #define GUARD(P) std::unique_ptr p##p(p, [](void*p){ GetHandle()->Release(p);}); 42 | -------------------------------------------------------------------------------- /Timer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | using namespace std; 4 | using namespace std::chrono; 5 | 6 | class Timer 7 | { 8 | public: 9 | Timer() : m_begin(high_resolution_clock::now()) {} 10 | void reset() { m_begin = high_resolution_clock::now(); } 11 | 12 | //默认输出毫秒 13 | int64_t elapsed() const 14 | { 15 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 16 | } 17 | 18 | //默认输出秒 19 | double elapsed_second() const 20 | { 21 | return duration_cast>(high_resolution_clock::now() - m_begin).count(); 22 | } 23 | 24 | //微秒 25 | int64_t elapsed_micro() const 26 | { 27 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 28 | } 29 | 30 | //纳秒 31 | int64_t elapsed_nano() const 32 | { 33 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 34 | } 35 | 36 | ////秒 37 | //int64_t elapsed_seconds() const 38 | //{ 39 | // return duration_cast(high_resolution_clock::now() - m_begin).count(); 40 | //} 41 | 42 | //分 43 | int64_t elapsed_minutes() const 44 | { 45 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 46 | } 47 | 48 | //时 49 | int64_t elapsed_hours() const 50 | { 51 | return duration_cast(high_resolution_clock::now() - m_begin).count(); 52 | } 53 | 54 | private: 55 | time_point m_begin; 56 | }; 57 | 58 | -------------------------------------------------------------------------------- /cache.hpp: -------------------------------------------------------------------------------- 1 | 2 | template 3 | std::function cache(R(*func) (Args...)) 4 | { 5 | auto result_map = std::make_shared, R>>(); 6 | 7 | return ([=](Args... args){ 8 | std::tuple t(args...); 9 | if (result_map->find(t) == result_map->end()) 10 | (*result_map)[t] = func(args...); 11 | 12 | return (*result_map)[t]; 13 | }); 14 | } 15 | 16 | template 17 | std::function sugar(R(*func)(Args...), bool needClear = false) 18 | { 19 | using function_type = std::function; 20 | static std::unordered_map functor_map; 21 | 22 | if (needClear) 23 | return functor_map[func] = cache(func); 24 | 25 | if (functor_map.find(func) == functor_map.end()) 26 | functor_map[func] = cache(func); 27 | 28 | return functor_map[func]; 29 | } 30 | 31 | 32 | /*test code 33 | size_t fibonacci(size_t n) 34 | { 35 | return (n < 2) ? n : sugar(fibonacci2)(n - 1) + sugar(fibonacci2)(n - 2); 36 | } 37 | 38 | 39 | */ 40 | -------------------------------------------------------------------------------- /cpp11book/rest_code.txt: -------------------------------------------------------------------------------- 1 | 第八章代码: 2 | https://github.com/qicosmos/cosmos/tree/master/pattern 3 | 4 | 第九章代码: 5 | https://github.com/qicosmos/cosmos/blob/master/ThreadPool.hpp 6 | https://github.com/qicosmos/cosmos/blob/master/SyncQueue.hpp 7 | 8 | 第十章代码: 9 | https://github.com/qicosmos/cosmos/blob/master/Aspect.hpp 10 | 11 | 第十一章代码: 12 | https://github.com/qicosmos/cosmos/blob/master/Ioc.hpp 13 | 14 | 第十二章代码: 15 | https://github.com/qicosmos/cosmos/blob/master/modern_messagebus.hpp 16 | 17 | 第十三章代码: 18 | https://github.com/qicosmos/SmartDB1.03 19 | 20 | 第十四章代码: 21 | https://github.com/qicosmos/cosmos/blob/master/LinqCpp.hpp 22 | 23 | 第十五章代码: 24 | https://github.com/qicosmos/TaskCppV1.1 25 | 26 | 第十六章代码: 27 | 参考boost官网c++11例子 28 | 29 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-1/1-1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-1", "1-1\1-1.vcxproj", "{BC3A3C7A-69F7-425C-8AE7-21EA3D6FE2B1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {BC3A3C7A-69F7-425C-8AE7-21EA3D6FE2B1}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {BC3A3C7A-69F7-425C-8AE7-21EA3D6FE2B1}.Debug|Win32.Build.0 = Debug|Win32 16 | {BC3A3C7A-69F7-425C-8AE7-21EA3D6FE2B1}.Release|Win32.ActiveCfg = Release|Win32 17 | {BC3A3C7A-69F7-425C-8AE7-21EA3D6FE2B1}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-1/1-1.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-1/1-1.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-1/1-1/1-1.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-1/1-1/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-1/1-1/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第一章/1-10/1-10.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-10", "1-10\1-10.vcxproj", "{40C8007B-2E93-4B95-B325-048B2CE5D650}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {40C8007B-2E93-4B95-B325-048B2CE5D650}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {40C8007B-2E93-4B95-B325-048B2CE5D650}.Debug|Win32.Build.0 = Debug|Win32 16 | {40C8007B-2E93-4B95-B325-048B2CE5D650}.Release|Win32.ActiveCfg = Release|Win32 17 | {40C8007B-2E93-4B95-B325-048B2CE5D650}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-10/1-10.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-10/1-10.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-10/1-10/1-10.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-10/1-10/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int a = 1.1; 6 | int b = { 1.1 }; //error 7 | 8 | float fa = 1e40; 9 | float fb = { 1e40 }; //error 10 | 11 | float fc = (unsigned long long)-1; 12 | float fd = { (unsigned long long)-1 }; //error 13 | float fe = (unsigned long long)1; 14 | float ff = { (unsigned long long)1 }; //OK 15 | 16 | const int x = 1024; 17 | const int y = 1; 18 | 19 | char c = x; 20 | char d = { x }; //error 21 | char e = y; 22 | char f = { y }; 23 | 24 | system("pause"); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /cpp11book/第一章/1-11~1-15/1-11~1-15.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-11~1-15", "1-11~1-15\1-11~1-15.vcxproj", "{B78D7E68-1406-4F93-9412-5AD11DA9625D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {B78D7E68-1406-4F93-9412-5AD11DA9625D}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {B78D7E68-1406-4F93-9412-5AD11DA9625D}.Debug|Win32.Build.0 = Debug|Win32 16 | {B78D7E68-1406-4F93-9412-5AD11DA9625D}.Release|Win32.ActiveCfg = Release|Win32 17 | {B78D7E68-1406-4F93-9412-5AD11DA9625D}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-11~1-15/1-11~1-15.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-11~1-15/1-11~1-15.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-11~1-15/1-11~1-15/1-11~1-15.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 23 | 24 | 源文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-11~1-15/1-11~1-15/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-11~1-15/1-11~1-15/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第一章/1-16/1-16.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-16", "1-16\1-16.vcxproj", "{FAD038A1-2B0D-4F05-81DF-B396C2AA8FDC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {FAD038A1-2B0D-4F05-81DF-B396C2AA8FDC}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {FAD038A1-2B0D-4F05-81DF-B396C2AA8FDC}.Debug|Win32.Build.0 = Debug|Win32 16 | {FAD038A1-2B0D-4F05-81DF-B396C2AA8FDC}.Release|Win32.ActiveCfg = Release|Win32 17 | {FAD038A1-2B0D-4F05-81DF-B396C2AA8FDC}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-16/1-16.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-16/1-16.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-16/1-16/1-16.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-16/1-16/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-16/1-16/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第一章/1-17/1-17.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-17", "1-17\1-17.vcxproj", "{4A6AF9FF-EABA-4A06-A3C3-C51F622B74BA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {4A6AF9FF-EABA-4A06-A3C3-C51F622B74BA}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {4A6AF9FF-EABA-4A06-A3C3-C51F622B74BA}.Debug|Win32.Build.0 = Debug|Win32 16 | {4A6AF9FF-EABA-4A06-A3C3-C51F622B74BA}.Release|Win32.ActiveCfg = Release|Win32 17 | {4A6AF9FF-EABA-4A06-A3C3-C51F622B74BA}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-17/1-17.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-17/1-17.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-17/1-17/1-17.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-17/1-17/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-17/1-17/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第一章/1-19/1-19.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-19", "1-19\1-19.vcxproj", "{6D28C409-B036-4F86-9206-B46365CB2FDF}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {6D28C409-B036-4F86-9206-B46365CB2FDF}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {6D28C409-B036-4F86-9206-B46365CB2FDF}.Debug|Win32.Build.0 = Debug|Win32 16 | {6D28C409-B036-4F86-9206-B46365CB2FDF}.Release|Win32.ActiveCfg = Release|Win32 17 | {6D28C409-B036-4F86-9206-B46365CB2FDF}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-19/1-19.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-19/1-19.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-19/1-19/1-19.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-19/1-19/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void call_when_even(int x, const std::function& f) 5 | { 6 | if (!(x & 1)) //x % 2 == 0 7 | { 8 | f(x); 9 | } 10 | } 11 | 12 | void output(int x) 13 | { 14 | std::cout << x << " "; 15 | } 16 | 17 | int main(void) 18 | { 19 | for (int i = 0; i < 10; ++i) 20 | { 21 | call_when_even(i, output); 22 | } 23 | 24 | std::cout << std::endl; 25 | 26 | system("pause"); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /cpp11book/第一章/1-2/1-2.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-2", "1-2\1-2.vcxproj", "{D0268220-6527-4136-8037-0ACA8B4B71C3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D0268220-6527-4136-8037-0ACA8B4B71C3}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {D0268220-6527-4136-8037-0ACA8B4B71C3}.Debug|Win32.Build.0 = Debug|Win32 16 | {D0268220-6527-4136-8037-0ACA8B4B71C3}.Release|Win32.ActiveCfg = Release|Win32 17 | {D0268220-6527-4136-8037-0ACA8B4B71C3}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-2/1-2.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-2/1-2.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-2/1-2/1-2.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-2/1-2/Test2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class Foo 4 | { 5 | public: 6 | static int get(void) 7 | { 8 | return 0; 9 | } 10 | }; 11 | 12 | class Bar 13 | { 14 | public: 15 | static const char* get(void) 16 | { 17 | return "0"; 18 | } 19 | }; 20 | 21 | template 22 | void func(void) 23 | { 24 | auto val = A::get(); 25 | 26 | //... 27 | } 28 | 29 | int main(void) 30 | { 31 | func(); 32 | func(); 33 | 34 | system("pause"); 35 | return 0; 36 | } -------------------------------------------------------------------------------- /cpp11book/第一章/1-20/1-20.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-20", "1-20\1-20.vcxproj", "{867654A2-388F-4390-B456-0E0A91A88333}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {867654A2-388F-4390-B456-0E0A91A88333}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {867654A2-388F-4390-B456-0E0A91A88333}.Debug|Win32.Build.0 = Debug|Win32 16 | {867654A2-388F-4390-B456-0E0A91A88333}.Release|Win32.ActiveCfg = Release|Win32 17 | {867654A2-388F-4390-B456-0E0A91A88333}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-20/1-20.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-20/1-20.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-20/1-20/1-20.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-20/1-20/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void call_when_even(int x, const std::function& f) 5 | { 6 | if (!(x & 1)) //x % 2 == 0 7 | { 8 | f(x); 9 | } 10 | } 11 | 12 | void output(int x) 13 | { 14 | std::cout << x << " "; 15 | } 16 | 17 | void output_add_2(int x) 18 | { 19 | std::cout << x + 2 << " "; 20 | } 21 | 22 | int main(void) 23 | { 24 | { 25 | auto fr = std::bind(output, std::placeholders::_1); 26 | for (int i = 0; i < 10; ++i) 27 | { 28 | call_when_even(i, fr); 29 | } 30 | 31 | std::cout << std::endl; 32 | } 33 | { 34 | auto fr = std::bind(output_add_2, std::placeholders::_1); 35 | 36 | for (int i = 0; i < 10; ++i) 37 | { 38 | call_when_even(i, fr); 39 | } 40 | 41 | std::cout << std::endl; 42 | } 43 | 44 | system("pause"); 45 | return 0; 46 | } -------------------------------------------------------------------------------- /cpp11book/第一章/1-21/1-21.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-21", "1-21\1-21.vcxproj", "{890E5376-D9B7-4946-B7C3-25CF02C271BC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {890E5376-D9B7-4946-B7C3-25CF02C271BC}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {890E5376-D9B7-4946-B7C3-25CF02C271BC}.Debug|Win32.Build.0 = Debug|Win32 16 | {890E5376-D9B7-4946-B7C3-25CF02C271BC}.Release|Win32.ActiveCfg = Release|Win32 17 | {890E5376-D9B7-4946-B7C3-25CF02C271BC}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-21/1-21.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-21/1-21.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-21/1-21/1-21.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-21/1-21/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-21/1-21/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第一章/1-22/1-22.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-22", "1-22\1-22.vcxproj", "{C09D1570-874F-4A5D-983D-D998AF36069A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C09D1570-874F-4A5D-983D-D998AF36069A}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {C09D1570-874F-4A5D-983D-D998AF36069A}.Debug|Win32.Build.0 = Debug|Win32 16 | {C09D1570-874F-4A5D-983D-D998AF36069A}.Release|Win32.ActiveCfg = Release|Win32 17 | {C09D1570-874F-4A5D-983D-D998AF36069A}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-22/1-22.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-22/1-22.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-22/1-22/1-22.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-22/1-22/test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-22/1-22/test.cpp -------------------------------------------------------------------------------- /cpp11book/第一章/1-23/1-23.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-23", "1-23\1-23.vcxproj", "{3A6C9AF8-7642-4FB5-9CA2-A74AD4B8FDFA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3A6C9AF8-7642-4FB5-9CA2-A74AD4B8FDFA}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {3A6C9AF8-7642-4FB5-9CA2-A74AD4B8FDFA}.Debug|Win32.Build.0 = Debug|Win32 16 | {3A6C9AF8-7642-4FB5-9CA2-A74AD4B8FDFA}.Release|Win32.ActiveCfg = Release|Win32 17 | {3A6C9AF8-7642-4FB5-9CA2-A74AD4B8FDFA}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-23/1-23.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-23/1-23.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-23/1-23/1-23.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-23/1-23/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-23/1-23/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第一章/1-24/1-24.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-24", "1-24\1-24.vcxproj", "{39F8331F-FBE9-47C9-8B07-3AD9B9D29093}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {39F8331F-FBE9-47C9-8B07-3AD9B9D29093}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {39F8331F-FBE9-47C9-8B07-3AD9B9D29093}.Debug|Win32.Build.0 = Debug|Win32 16 | {39F8331F-FBE9-47C9-8B07-3AD9B9D29093}.Release|Win32.ActiveCfg = Release|Win32 17 | {39F8331F-FBE9-47C9-8B07-3AD9B9D29093}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-24/1-24.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-24/1-24.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-24/1-24/1-24.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-24/1-24/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | class CountEven 6 | { 7 | int& count_; 8 | 9 | public: 10 | CountEven(int& count) : count_(count){} 11 | 12 | void operator()(int val) 13 | { 14 | if (!(val & 1)) //val % 2 == 0 15 | { 16 | ++count_; 17 | } 18 | } 19 | }; 20 | 21 | 22 | int main(void) 23 | { 24 | std::vector v = { 1, 2, 3, 4, 5, 6 }; 25 | int even_count = 0; 26 | 27 | std::for_each(v.begin(), v.end(), CountEven(even_count)); 28 | std::cout << "The number of even is " << even_count << std::endl; 29 | 30 | system("pause"); 31 | return 0; 32 | } -------------------------------------------------------------------------------- /cpp11book/第一章/1-3/1-3.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-3", "1-3\1-3.vcxproj", "{33FAE1E9-305E-4678-823E-A5E25B6FE82C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {33FAE1E9-305E-4678-823E-A5E25B6FE82C}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {33FAE1E9-305E-4678-823E-A5E25B6FE82C}.Debug|Win32.Build.0 = Debug|Win32 16 | {33FAE1E9-305E-4678-823E-A5E25B6FE82C}.Release|Win32.ActiveCfg = Release|Win32 17 | {33FAE1E9-305E-4678-823E-A5E25B6FE82C}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-3/1-3.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-3/1-3.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-3/1-3/1-3.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-3/1-3/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class Foo 4 | { 5 | public: 6 | static const int Number = 0; 7 | int x; 8 | }; 9 | 10 | int main(void) 11 | { 12 | int n = 0; 13 | volatile const int &x = n; 14 | 15 | decltype(n) a = n; //a -> int 16 | decltype(x) b = n; //b -> const volatile int & 17 | 18 | decltype(Foo::Number) c = 0; //c -> const int 19 | 20 | system("pause"); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /cpp11book/第一章/1-4/1-4.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-4", "1-4\1-4.vcxproj", "{FFC73B1E-D9AC-4AA3-934A-E07B4BFF6447}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {FFC73B1E-D9AC-4AA3-934A-E07B4BFF6447}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {FFC73B1E-D9AC-4AA3-934A-E07B4BFF6447}.Debug|Win32.Build.0 = Debug|Win32 16 | {FFC73B1E-D9AC-4AA3-934A-E07B4BFF6447}.Release|Win32.ActiveCfg = Release|Win32 17 | {FFC73B1E-D9AC-4AA3-934A-E07B4BFF6447}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-4/1-4.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-4/1-4.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-4/1-4/1-4.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-4/1-4/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-4/1-4/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第一章/1-5/1-5.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-5", "1-5\1-5.vcxproj", "{1142DE3A-EB62-4D94-B6AF-3E85B427C19A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {1142DE3A-EB62-4D94-B6AF-3E85B427C19A}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {1142DE3A-EB62-4D94-B6AF-3E85B427C19A}.Debug|Win32.Build.0 = Debug|Win32 16 | {1142DE3A-EB62-4D94-B6AF-3E85B427C19A}.Release|Win32.ActiveCfg = Release|Win32 17 | {1142DE3A-EB62-4D94-B6AF-3E85B427C19A}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-5/1-5.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-5/1-5.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-5/1-5/1-5.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-5/1-5/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-5/1-5/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第一章/1-7/1-7.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-7", "1-7\1-7.vcxproj", "{7320E126-0B1D-4F9C-BDE3-F2ECE5D8CC8C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {7320E126-0B1D-4F9C-BDE3-F2ECE5D8CC8C}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {7320E126-0B1D-4F9C-BDE3-F2ECE5D8CC8C}.Debug|Win32.Build.0 = Debug|Win32 16 | {7320E126-0B1D-4F9C-BDE3-F2ECE5D8CC8C}.Release|Win32.ActiveCfg = Release|Win32 17 | {7320E126-0B1D-4F9C-BDE3-F2ECE5D8CC8C}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-7/1-7.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-7/1-7.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-7/1-7/1-7.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-7/1-7/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-7/1-7/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第一章/1-8/1-8.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-8", "1-8\1-8.vcxproj", "{469D305A-5E0A-4EC3-BBBD-8A059EA0E2AD}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {469D305A-5E0A-4EC3-BBBD-8A059EA0E2AD}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {469D305A-5E0A-4EC3-BBBD-8A059EA0E2AD}.Debug|Win32.Build.0 = Debug|Win32 16 | {469D305A-5E0A-4EC3-BBBD-8A059EA0E2AD}.Release|Win32.ActiveCfg = Release|Win32 17 | {469D305A-5E0A-4EC3-BBBD-8A059EA0E2AD}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-8/1-8.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-8/1-8.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-8/1-8/1-8.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-8/1-8/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-8/1-8/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第一章/1-9/1-9.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1-9", "1-9\1-9.vcxproj", "{3A8B38F9-67AC-4325-9129-20FCF2EFB30F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3A8B38F9-67AC-4325-9129-20FCF2EFB30F}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {3A8B38F9-67AC-4325-9129-20FCF2EFB30F}.Debug|Win32.Build.0 = Debug|Win32 16 | {3A8B38F9-67AC-4325-9129-20FCF2EFB30F}.Release|Win32.ActiveCfg = Release|Win32 17 | {3A8B38F9-67AC-4325-9129-20FCF2EFB30F}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-9/1-9.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/1-9/1-9.v12.suo -------------------------------------------------------------------------------- /cpp11book/第一章/1-9/1-9/1-9.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第一章/1-9/1-9/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | class FooVector 6 | { 7 | std::vector content_; 8 | 9 | public: 10 | FooVector(std::initializer_list list) 11 | { 12 | for (auto it = list.begin(); it != list.end(); ++it) 13 | { 14 | content_.push_back(*it); 15 | } 16 | } 17 | }; 18 | 19 | class FooMap 20 | { 21 | std::map content_; 22 | using pair_t = std::map::value_type; 23 | 24 | public: 25 | FooMap(std::initializer_list list) 26 | { 27 | for (auto it = list.begin(); it != list.end(); ++it) 28 | { 29 | content_.insert(*it); 30 | } 31 | } 32 | }; 33 | 34 | int main(void) 35 | { 36 | FooVector foo1 = { 1, 2, 3, 4, 5 }; 37 | FooMap foo2 = { { 1, 2 }, { 3, 4 }, { 5, 6 } }; 38 | 39 | system("pause"); 40 | return 0; 41 | } -------------------------------------------------------------------------------- /cpp11book/第一章/VC清理助手.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第一章/VC清理助手.bat -------------------------------------------------------------------------------- /cpp11book/第三章/3-1/3-1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-1", "3-1\3-1.vcxproj", "{9BF2F713-25CB-4222-892B-F154A2E651CB}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {9BF2F713-25CB-4222-892B-F154A2E651CB}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {9BF2F713-25CB-4222-892B-F154A2E651CB}.Debug|Win32.Build.0 = Debug|Win32 16 | {9BF2F713-25CB-4222-892B-F154A2E651CB}.Release|Win32.ActiveCfg = Release|Win32 17 | {9BF2F713-25CB-4222-892B-F154A2E651CB}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-1/3-1.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-1/3-1.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-1/3-1/3-1.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-1/3-1/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-1/3-1/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第三章/3-10/3-10.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-10", "3-10\3-10.vcxproj", "{CFAFC979-F3AB-4C2D-99C7-6150725210B9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {CFAFC979-F3AB-4C2D-99C7-6150725210B9}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {CFAFC979-F3AB-4C2D-99C7-6150725210B9}.Debug|Win32.Build.0 = Debug|Win32 16 | {CFAFC979-F3AB-4C2D-99C7-6150725210B9}.Release|Win32.ActiveCfg = Release|Win32 17 | {CFAFC979-F3AB-4C2D-99C7-6150725210B9}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-10/3-10.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-10/3-10.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-10/3-10/3-10.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-10/3-10/DllParser.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _DLLPARSER_HPP_ 2 | #define _DLLPARSER_HPP_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | class DllParser 12 | { 13 | public: 14 | 15 | DllParser() 16 | { 17 | } 18 | 19 | ~DllParser() 20 | { 21 | UnLoad(); 22 | } 23 | 24 | bool Load(const std::string& dllPath) 25 | { 26 | m_hMod = LoadLibrary(dllPath.data()); 27 | if (nullptr == m_hMod) 28 | { 29 | std::cout << "LoadLibrary failed\n"; 30 | return false; 31 | } 32 | 33 | return true; 34 | } 35 | 36 | template 37 | typename std::result_of(Args...)>::type 38 | ExcecuteFunc(const std::string& funcName, Args&&... args) 39 | { 40 | auto f = GetFunction(funcName); 41 | 42 | if (f == nullptr) 43 | { 44 | std::string s = "can not find this function " + funcName; 45 | throw std::exception(s.c_str()); 46 | } 47 | 48 | return f(std::forward(args)...); 49 | } 50 | 51 | private: 52 | bool UnLoad() 53 | { 54 | if (m_hMod == nullptr) 55 | return true; 56 | 57 | auto b = FreeLibrary(m_hMod); 58 | if (!b) 59 | return false; 60 | 61 | m_hMod = nullptr; 62 | return true; 63 | } 64 | 65 | template 66 | T* GetFunction(const std::string& funcName) 67 | { 68 | auto addr = GetProcAddress(m_hMod, funcName.c_str()); 69 | return (T*) (addr); 70 | } 71 | 72 | private: 73 | HMODULE m_hMod; 74 | std::map m_map; 75 | }; 76 | 77 | #endif //_DLLPARSER_HPP_ -------------------------------------------------------------------------------- /cpp11book/第三章/3-10/3-10/MyDLL.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-10/3-10/MyDLL.dll -------------------------------------------------------------------------------- /cpp11book/第三章/3-10/3-10/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "DllParser.hpp" 2 | 3 | #include 4 | 5 | void TestDllParser() 6 | { 7 | DllParser dllParser; 8 | std::string str("MyDLL.dll"); 9 | 10 | dllParser.Load(str); 11 | 12 | int a = 5; 13 | int b = 8; 14 | 15 | auto max = dllParser.ExcecuteFunc("Max", a, b); 16 | auto add = dllParser.ExcecuteFunc("Add", a, b); 17 | } 18 | 19 | int main(void) 20 | { 21 | TestDllParser(); 22 | 23 | system("pause"); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /cpp11book/第三章/3-12/3-12.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-12", "3-12\3-12.vcxproj", "{D0F664EA-7B1D-4E0B-8DF1-FF2714B3249F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D0F664EA-7B1D-4E0B-8DF1-FF2714B3249F}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {D0F664EA-7B1D-4E0B-8DF1-FF2714B3249F}.Debug|Win32.Build.0 = Debug|Win32 16 | {D0F664EA-7B1D-4E0B-8DF1-FF2714B3249F}.Release|Win32.ActiveCfg = Release|Win32 17 | {D0F664EA-7B1D-4E0B-8DF1-FF2714B3249F}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-12/3-12.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-12/3-12.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-12/3-12/3-12.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-12/3-12/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | template 6 | class Task; 7 | 8 | template 9 | class Task 10 | { 11 | public: 12 | Task(std::function&& f) : m_fn(std::move(f)){} 13 | 14 | Task(std::function& f) : m_fn(f){} 15 | 16 | template 17 | R Run(Args&&... args) 18 | { 19 | return m_fn(std::forward(args)...); 20 | } 21 | 22 | template 23 | auto Then(F& f)->Task::type(Args...)> 24 | { 25 | using return_type = typename std::result_of::type; 26 | 27 | auto func = std::move(m_fn); 28 | 29 | return Task([func, f](Args&&... args) 30 | {return f(func(std::forward(args)...)); }); 31 | } 32 | 33 | private: 34 | std::function m_fn; 35 | }; 36 | 37 | 38 | void TestTask() 39 | { 40 | Task task = [](int i){ return i; }; 41 | auto result = task.Then([](int i){return i + 1; }).Then([](int i){ 42 | return i + 2; }).Then([](int i){return i + 3; }).Run(1); 43 | std::cout << result << std::endl; // 7 44 | } 45 | 46 | 47 | int main(void) 48 | { 49 | TestTask(); 50 | 51 | system("pause"); 52 | return 0; 53 | } -------------------------------------------------------------------------------- /cpp11book/第三章/3-13/3-13.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-13", "3-13\3-13.vcxproj", "{A2E9935B-1116-4AF6-AF54-95A89DEE9991}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {A2E9935B-1116-4AF6-AF54-95A89DEE9991}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {A2E9935B-1116-4AF6-AF54-95A89DEE9991}.Debug|Win32.Build.0 = Debug|Win32 16 | {A2E9935B-1116-4AF6-AF54-95A89DEE9991}.Release|Win32.ActiveCfg = Release|Win32 17 | {A2E9935B-1116-4AF6-AF54-95A89DEE9991}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-13/3-13.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-13/3-13.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-13/3-13/3-13.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-13/3-13/Any.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-13/3-13/Any.hpp -------------------------------------------------------------------------------- /cpp11book/第三章/3-13/3-13/源.cpp: -------------------------------------------------------------------------------- 1 | #include "Any.hpp" 2 | 3 | #include 4 | #include 5 | 6 | void TestAny() 7 | { 8 | Any n; 9 | auto r = n.IsNull();//true 10 | std::string s1 = "hello"; 11 | n = s1; 12 | n = "world"; 13 | n.AnyCast(); //can not cast int to string 14 | Any n1 = 1; 15 | n1.Is(); //true 16 | } 17 | 18 | 19 | int main(void) 20 | { 21 | TestAny(); 22 | 23 | system("pause"); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /cpp11book/第三章/3-14/3-14.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-14", "3-14\3-14.vcxproj", "{60EA4721-32F7-4B2E-BF2A-93B128103389}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {60EA4721-32F7-4B2E-BF2A-93B128103389}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {60EA4721-32F7-4B2E-BF2A-93B128103389}.Debug|Win32.Build.0 = Debug|Win32 16 | {60EA4721-32F7-4B2E-BF2A-93B128103389}.Release|Win32.ActiveCfg = Release|Win32 17 | {60EA4721-32F7-4B2E-BF2A-93B128103389}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-14/3-14.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-14/3-14.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-14/3-14/3-14.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-14/3-14/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct VariantVisitor : public boost::static_visitor 6 | { 7 | void operator()(int a) 8 | { 9 | std::cout << "int" << std::endl; 10 | } 11 | void operator()(short a) 12 | { 13 | std::cout << "short" << std::endl; 14 | } 15 | void operator()(double a) 16 | { 17 | std::cout << "double" << std::endl; 18 | } 19 | void operator()(std::string a) 20 | { 21 | std::cout << "std::string" << std::endl; 22 | } 23 | }; 24 | 25 | 26 | int main(void) 27 | { 28 | VariantVisitor visitor; 29 | boost::variant v = 1; 30 | boost::apply_visitor(visitor, v); 31 | 32 | system("pause"); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /cpp11book/第三章/3-15/3-15.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-15", "3-15\3-15.vcxproj", "{22C63550-2D20-4B58-81C5-EE0B61EF1329}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {22C63550-2D20-4B58-81C5-EE0B61EF1329}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {22C63550-2D20-4B58-81C5-EE0B61EF1329}.Debug|Win32.Build.0 = Debug|Win32 16 | {22C63550-2D20-4B58-81C5-EE0B61EF1329}.Release|Win32.ActiveCfg = Release|Win32 17 | {22C63550-2D20-4B58-81C5-EE0B61EF1329}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-15/3-15.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-15/3-15.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-15/3-15/3-15.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-15/3-15/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-15/3-15/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第三章/3-15/3-15/Variant.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-15/3-15/Variant.hpp -------------------------------------------------------------------------------- /cpp11book/第三章/3-16/3-16.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-16", "3-16\3-16.vcxproj", "{AAD898B8-CAAB-4ECE-80F1-0241967C2FC2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {AAD898B8-CAAB-4ECE-80F1-0241967C2FC2}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {AAD898B8-CAAB-4ECE-80F1-0241967C2FC2}.Debug|Win32.Build.0 = Debug|Win32 16 | {AAD898B8-CAAB-4ECE-80F1-0241967C2FC2}.Release|Win32.ActiveCfg = Release|Win32 17 | {AAD898B8-CAAB-4ECE-80F1-0241967C2FC2}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-16/3-16.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-16/3-16.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-16/3-16/3-16.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-16/3-16/ScopeGuard.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _SCOPEGUARD_HPP_ 2 | #define _SCOPEGUARD_HPP_ 3 | 4 | #include 5 | 6 | template 7 | class ScopeGuard 8 | { 9 | public: 10 | explicit ScopeGuard( F && f) : m_func(std::move(f)), m_dismiss(false){} 11 | explicit ScopeGuard(const F& f) : m_func(f), m_dismiss(false){} 12 | 13 | ~ScopeGuard() 14 | { 15 | if (!m_dismiss) 16 | m_func(); 17 | } 18 | 19 | ScopeGuard(ScopeGuard && rhs) : m_func(std::move(rhs.m_func)), 20 | m_dismiss(rhs.m_dismiss) 21 | { 22 | rhs.Dismiss(); 23 | } 24 | 25 | void Dismiss() 26 | { 27 | m_dismiss = true; 28 | } 29 | 30 | private: 31 | F m_func; 32 | bool m_dismiss; 33 | 34 | ScopeGuard(); 35 | ScopeGuard(const ScopeGuard&); 36 | ScopeGuard& operator=(const ScopeGuard&); 37 | }; 38 | 39 | 40 | template 41 | ScopeGuard::type> MakeGuard(F && f) 42 | { 43 | return ScopeGuard::type>(std::forward(f)); 44 | } 45 | 46 | 47 | #endif //_SCOPEGUARD_HPP_ -------------------------------------------------------------------------------- /cpp11book/第三章/3-16/3-16/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-16/3-16/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第三章/3-17/3-17.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-17", "3-17\3-17.vcxproj", "{69B2B228-020E-4129-B214-16CD46CA4AE3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {69B2B228-020E-4129-B214-16CD46CA4AE3}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {69B2B228-020E-4129-B214-16CD46CA4AE3}.Debug|Win32.Build.0 = Debug|Win32 16 | {69B2B228-020E-4129-B214-16CD46CA4AE3}.Release|Win32.ActiveCfg = Release|Win32 17 | {69B2B228-020E-4129-B214-16CD46CA4AE3}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-17/3-17.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-17/3-17.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-17/3-17/3-17.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-17/3-17/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-17/3-17/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第三章/3-18/3-18.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-18", "3-18\3-18.vcxproj", "{451BAD48-E14F-44DA-8DF7-2C9E962375A0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {451BAD48-E14F-44DA-8DF7-2C9E962375A0}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {451BAD48-E14F-44DA-8DF7-2C9E962375A0}.Debug|Win32.Build.0 = Debug|Win32 16 | {451BAD48-E14F-44DA-8DF7-2C9E962375A0}.Release|Win32.ActiveCfg = Release|Win32 17 | {451BAD48-E14F-44DA-8DF7-2C9E962375A0}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-18/3-18.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-18/3-18.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-18/3-18/3-18.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-18/3-18/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | template 5 | struct IndexTuple {}; 6 | 7 | template 8 | struct MakeIndexes : MakeIndexes{}; 9 | 10 | template 11 | struct MakeIndexes<0, Indexs...> 12 | { 13 | typedef IndexTuple type; 14 | }; 15 | 16 | template 17 | void Print(T t) 18 | { 19 | std::cout << t << std::endl; 20 | } 21 | 22 | template 23 | void Print(T t, Args...args) 24 | { 25 | std::cout << t << std::endl; 26 | Print(args...); 27 | } 28 | 29 | template 30 | void Transform(IndexTuple& in, Tuple& tp) 31 | { 32 | Print(std::get(tp)...); 33 | } 34 | 35 | int main(void) 36 | { 37 | using Tuple = std::tuple; 38 | Tuple tp = std::make_tuple(1, 2); 39 | Transform(MakeIndexes::value>::type(), tp); 40 | 41 | system("pause"); 42 | return 0; 43 | } -------------------------------------------------------------------------------- /cpp11book/第三章/3-19/3-19.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-19", "3-19\3-19.vcxproj", "{77E4E1FD-63B3-4F4C-8472-22AA46616986}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {77E4E1FD-63B3-4F4C-8472-22AA46616986}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {77E4E1FD-63B3-4F4C-8472-22AA46616986}.Debug|Win32.Build.0 = Debug|Win32 16 | {77E4E1FD-63B3-4F4C-8472-22AA46616986}.Release|Win32.ActiveCfg = Release|Win32 17 | {77E4E1FD-63B3-4F4C-8472-22AA46616986}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-19/3-19.v11.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-19/3-19.v11.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-19/3-19.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-19/3-19.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-19/3-19/3-19.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-19/3-19/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-19/3-19/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第三章/3-2/3-2.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-2", "3-2\3-2.vcxproj", "{7B1E989A-DEF3-48DF-9F53-4D4E69EA42A9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {7B1E989A-DEF3-48DF-9F53-4D4E69EA42A9}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {7B1E989A-DEF3-48DF-9F53-4D4E69EA42A9}.Debug|Win32.Build.0 = Debug|Win32 16 | {7B1E989A-DEF3-48DF-9F53-4D4E69EA42A9}.Release|Win32.ActiveCfg = Release|Win32 17 | {7B1E989A-DEF3-48DF-9F53-4D4E69EA42A9}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-2/3-2.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-2/3-2.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-2/3-2/3-2.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-2/3-2/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int fn(int){ return int(); } 5 | typedef int(&fn_ref)(int); 6 | typedef int(*fn_ptr)(int); 7 | struct fn_class 8 | { 9 | int operator()(int i) 10 | { 11 | return i; 12 | } 13 | }; 14 | 15 | int main(void) 16 | { 17 | typedef std::result_of::type A; //int 18 | typedef std::result_of::type B; //int 19 | typedef std::result_of::type C; //int 20 | typedef std::result_of::type D; //int 21 | 22 | std::cout << std::boolalpha; 23 | std::cout << "typedefs of int:" << std::endl; 24 | 25 | std::cout << "A: " << std::is_same::value << std::endl; 26 | std::cout << "B: " << std::is_same::value << std::endl; 27 | std::cout << "C: " << std::is_same::value << std::endl; 28 | std::cout << "D: " << std::is_same::value << std::endl; 29 | 30 | system("pause"); 31 | return 0; 32 | } -------------------------------------------------------------------------------- /cpp11book/第三章/3-20/3-20.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-20", "3-20\3-20.vcxproj", "{DB3B5D32-304E-4B68-A656-63CE731684B8}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {DB3B5D32-304E-4B68-A656-63CE731684B8}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {DB3B5D32-304E-4B68-A656-63CE731684B8}.Debug|Win32.Build.0 = Debug|Win32 16 | {DB3B5D32-304E-4B68-A656-63CE731684B8}.Release|Win32.ActiveCfg = Release|Win32 17 | {DB3B5D32-304E-4B68-A656-63CE731684B8}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-20/3-20.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-20/3-20.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-20/3-20/3-20.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-20/3-20/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-20/3-20/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第三章/3-21/3-21.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-21", "3-21\3-21.vcxproj", "{78169344-072E-4161-9012-5A42E3E1B494}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {78169344-072E-4161-9012-5A42E3E1B494}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {78169344-072E-4161-9012-5A42E3E1B494}.Debug|Win32.Build.0 = Debug|Win32 16 | {78169344-072E-4161-9012-5A42E3E1B494}.Release|Win32.ActiveCfg = Release|Win32 17 | {78169344-072E-4161-9012-5A42E3E1B494}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-21/3-21.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-21/3-21.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-21/3-21/3-21.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-21/3-21/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-21/3-21/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第三章/3-22/3-22.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-22", "3-22\3-22.vcxproj", "{AEA071FA-EE0A-4063-B0B9-C62BEE439F6B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {AEA071FA-EE0A-4063-B0B9-C62BEE439F6B}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {AEA071FA-EE0A-4063-B0B9-C62BEE439F6B}.Debug|Win32.Build.0 = Debug|Win32 16 | {AEA071FA-EE0A-4063-B0B9-C62BEE439F6B}.Release|Win32.ActiveCfg = Release|Win32 17 | {AEA071FA-EE0A-4063-B0B9-C62BEE439F6B}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-22/3-22.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-22/3-22.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-22/3-22/3-22.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 26 | 27 | 源文件 28 | 29 | 30 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-22/3-22/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "TpForeach.hpp" 2 | #include 3 | 4 | struct Functor 5 | { 6 | template 7 | void operator()(T& t) const 8 | { 9 | //t.doSomething(); 10 | std::cout << t << std::endl; 11 | } 12 | }; 13 | 14 | void TestTupleForeach() 15 | { 16 | tp_for_each(Functor(), std::make_tuple(1, 2.5)); 17 | } 18 | 19 | int main(void) 20 | { 21 | TestTupleForeach(); 22 | 23 | system("pause"); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /cpp11book/第三章/3-22/3-22/TpForeach.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "TpIndexs.hpp" 3 | 4 | #include 5 | 6 | namespace details { 7 | 8 | template 9 | void for_each_impl(Func&& f, Last&& last) 10 | { 11 | f(last); 12 | } 13 | 14 | template 15 | void for_each_impl(Func&& f, First&& first, Rest&&...rest) 16 | { 17 | f(first); 18 | for_each_impl(std::forward(f), rest...); 19 | } 20 | 21 | template 22 | void for_each_helper(Func&& f, IndexTuple, std::tuple&& tup) 23 | { 24 | for_each_impl(std::forward(f), std::forward(std::get(tup))...); 25 | } 26 | 27 | } // namespace details 28 | 29 | template 30 | void tp_for_each(Func&& f, Tuple& tup) 31 | { 32 | using namespace details; 33 | for_each_helper(std::forward(f), typename make_indexes< 34 | std::tuple_size::value>::type(), tup); 35 | } 36 | 37 | template 38 | void tp_for_each(Func&& f, Tuple&& tup) 39 | { 40 | using namespace details; 41 | for_each_helper(std::forward(f), typename make_indexes< 42 | std::tuple_size::value>::type(), 43 | std::forward(tup)); 44 | } 45 | 46 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-22/3-22/TpIndexs.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | template 4 | struct IndexTuple {}; 5 | 6 | template 7 | struct make_indexes : make_indexes{}; 8 | 9 | template 10 | struct make_indexes<0, Indexs...> 11 | { 12 | typedef IndexTuple type; 13 | }; -------------------------------------------------------------------------------- /cpp11book/第三章/3-23/3-23.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-23", "3-23\3-23.vcxproj", "{9A43F963-7DD3-4A6F-8833-8523F6E6F70C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {9A43F963-7DD3-4A6F-8833-8523F6E6F70C}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {9A43F963-7DD3-4A6F-8833-8523F6E6F70C}.Debug|Win32.Build.0 = Debug|Win32 16 | {9A43F963-7DD3-4A6F-8833-8523F6E6F70C}.Release|Win32.ActiveCfg = Release|Win32 17 | {9A43F963-7DD3-4A6F-8833-8523F6E6F70C}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-23/3-23.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-23/3-23.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-23/3-23/3-23.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-23/3-23/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-23/3-23/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第三章/3-24/3-24.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-24", "3-24\3-24.vcxproj", "{1E29FCA4-09EF-45F9-B364-86A76A6D08C9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {1E29FCA4-09EF-45F9-B364-86A76A6D08C9}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {1E29FCA4-09EF-45F9-B364-86A76A6D08C9}.Debug|Win32.Build.0 = Debug|Win32 16 | {1E29FCA4-09EF-45F9-B364-86A76A6D08C9}.Release|Win32.ActiveCfg = Release|Win32 17 | {1E29FCA4-09EF-45F9-B364-86A76A6D08C9}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-24/3-24.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-24/3-24.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-24/3-24/3-24.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-24/3-24/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-24/3-24/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第三章/3-25/3-25.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-25", "3-25\3-25.vcxproj", "{56F07ED4-6404-4880-8B71-9A86A5A542B5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {56F07ED4-6404-4880-8B71-9A86A5A542B5}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {56F07ED4-6404-4880-8B71-9A86A5A542B5}.Debug|Win32.Build.0 = Debug|Win32 16 | {56F07ED4-6404-4880-8B71-9A86A5A542B5}.Release|Win32.ActiveCfg = Release|Win32 17 | {56F07ED4-6404-4880-8B71-9A86A5A542B5}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-25/3-25.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-25/3-25.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-25/3-25/3-25.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 23 | 24 | 源文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-25/3-25/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "TpZip.hpp" 2 | #include 3 | 4 | void TupleZip() 5 | { 6 | auto tp1 = std::make_tuple(1, 2, 2.5, 'a'); 7 | auto tp2 = std::make_tuple(1.5, 2, 2.5, 'z'); 8 | auto mypairs = Zip(tp1, tp2); 9 | } 10 | 11 | int main(void) 12 | { 13 | TupleZip(); 14 | 15 | system("pause"); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /cpp11book/第三章/3-25/3-25/TpZip.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-25/3-25/TpZip.hpp -------------------------------------------------------------------------------- /cpp11book/第三章/3-3/3-3.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-3", "3-3\3-3.vcxproj", "{44B97157-A8C6-4E8B-B4B4-C5EB6937A8A5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {44B97157-A8C6-4E8B-B4B4-C5EB6937A8A5}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {44B97157-A8C6-4E8B-B4B4-C5EB6937A8A5}.Debug|Win32.Build.0 = Debug|Win32 16 | {44B97157-A8C6-4E8B-B4B4-C5EB6937A8A5}.Release|Win32.ActiveCfg = Release|Win32 17 | {44B97157-A8C6-4E8B-B4B4-C5EB6937A8A5}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-3/3-3.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-3/3-3.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-3/3-3/3-3.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-3/3-3/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | template 4 | void Print(T t) 5 | { 6 | std::cout << t << std::endl; 7 | } 8 | 9 | template 10 | void Print(T1 t1, T2 t2) 11 | { 12 | std::cout << t1 << t2 << std::endl; 13 | } 14 | 15 | template 16 | void Print(T1 t1, T2 t2, T3 t3) 17 | { 18 | std::cout << t1 << t2 << t3 << std::endl; 19 | } 20 | 21 | template 22 | void Print(T1 t1, T2 t2, T3 t3, T4 t4) 23 | { 24 | std::cout << t1 << t2 << t3 << t4 << std::endl; 25 | } 26 | 27 | template 28 | void Print(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) 29 | { 30 | std::cout << t1 << t2 << t3 << t4 << t5 << std::endl; 31 | } 32 | 33 | int main(void) 34 | { 35 | Print(1); 36 | Print(1, 2); 37 | Print(1, 2, 3); 38 | Print(1, 2, 3, 4); 39 | Print(1, 2, 3, 4, 5); 40 | 41 | 42 | system("pause"); 43 | return 0; 44 | } -------------------------------------------------------------------------------- /cpp11book/第三章/3-4/3-4.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-4", "3-4\3-4.vcxproj", "{12BF5893-5843-4DAD-8E10-BB8BE6E5B1DD}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {12BF5893-5843-4DAD-8E10-BB8BE6E5B1DD}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {12BF5893-5843-4DAD-8E10-BB8BE6E5B1DD}.Debug|Win32.Build.0 = Debug|Win32 16 | {12BF5893-5843-4DAD-8E10-BB8BE6E5B1DD}.Release|Win32.ActiveCfg = Release|Win32 17 | {12BF5893-5843-4DAD-8E10-BB8BE6E5B1DD}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-4/3-4.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-4/3-4.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-4/3-4/3-4.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-4/3-4/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | template 4 | T* Instance() 5 | { 6 | return new T(); 7 | } 8 | 9 | template 10 | T* Instance(T0 arg0) 11 | { 12 | return new T(arg0); 13 | } 14 | 15 | 16 | template 17 | T* Instance(T0 arg0, T1 arg1) 18 | { 19 | return new T(arg0, arg1); 20 | } 21 | 22 | template 23 | T* Instance(T0 arg0, T1 arg1, T2 arg2) 24 | { 25 | return new T(arg0, arg1, arg2); 26 | } 27 | 28 | template 29 | T* Instance(T0 arg0, T1 arg1, T2 arg2, T3 arg3) 30 | { 31 | return new T(arg0, arg1, arg2, arg3); 32 | } 33 | 34 | template 35 | T* Instance(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) 36 | { 37 | return new T(arg0, arg1, arg2, arg3, arg4); 38 | } 39 | 40 | struct A 41 | { 42 | A(int){} 43 | }; 44 | 45 | struct B 46 | { 47 | B(int, double){} 48 | }; 49 | 50 | int main(void) 51 | { 52 | A* pa = Instance(1); 53 | B* pb = Instance(1, 2); 54 | 55 | system("pause"); 56 | return 0; 57 | } -------------------------------------------------------------------------------- /cpp11book/第三章/3-5/3-5.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-5", "3-5\3-5.vcxproj", "{F0AE1FC1-65E7-4FC1-9AC6-57F7370A783C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {F0AE1FC1-65E7-4FC1-9AC6-57F7370A783C}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {F0AE1FC1-65E7-4FC1-9AC6-57F7370A783C}.Debug|Win32.Build.0 = Debug|Win32 16 | {F0AE1FC1-65E7-4FC1-9AC6-57F7370A783C}.Release|Win32.ActiveCfg = Release|Win32 17 | {F0AE1FC1-65E7-4FC1-9AC6-57F7370A783C}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-5/3-5.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-5/3-5.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-5/3-5/3-5.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-5/3-5/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-5/3-5/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第三章/3-5/3-5/optional.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-5/3-5/optional.hpp -------------------------------------------------------------------------------- /cpp11book/第三章/3-7~3-8/3-7~3-8.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-7~3-8", "3-7~3-8\3-7~3-8.vcxproj", "{FAF116AE-96D9-4713-A596-95ED7E11A7D5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {FAF116AE-96D9-4713-A596-95ED7E11A7D5}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {FAF116AE-96D9-4713-A596-95ED7E11A7D5}.Debug|Win32.Build.0 = Debug|Win32 16 | {FAF116AE-96D9-4713-A596-95ED7E11A7D5}.Release|Win32.ActiveCfg = Release|Win32 17 | {FAF116AE-96D9-4713-A596-95ED7E11A7D5}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-7~3-8/3-7~3-8.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-7~3-8/3-7~3-8.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-7~3-8/3-7~3-8/3-7~3-8.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 23 | 24 | 源文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-7~3-8/3-7~3-8/Lazy.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _LAZY_HPP_ 2 | #define _LAZY_HPP_ 3 | 4 | #include 5 | template 6 | struct Lazy 7 | { 8 | Lazy(){} 9 | 10 | template 11 | Lazy(Func& f, Args && ... args) 12 | { 13 | m_func = [&f, &args...]{return f(args...); }; 14 | } 15 | 16 | T& Value() 17 | { 18 | if (!m_value.is_initialized()) 19 | { 20 | m_value = m_func(); 21 | } 22 | 23 | return *m_value; 24 | } 25 | 26 | bool IsValueCreated() const 27 | { 28 | return m_value.is_initialized(); 29 | } 30 | 31 | private: 32 | std::function m_func; 33 | boost::optional m_value; 34 | }; 35 | 36 | template 37 | Lazy::type> 38 | lazy(Func && fun, Args && ... args) 39 | { 40 | return Lazy::type>( 41 | std::forward(fun), std::forward(args)...); 42 | } 43 | 44 | 45 | #endif -------------------------------------------------------------------------------- /cpp11book/第三章/3-7~3-8/3-7~3-8/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-7~3-8/3-7~3-8/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第三章/3-9/3-9.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3-9", "3-9\3-9.vcxproj", "{73A4A9B6-0981-4BBE-B452-41DFB0761D5C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {73A4A9B6-0981-4BBE-B452-41DFB0761D5C}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {73A4A9B6-0981-4BBE-B452-41DFB0761D5C}.Debug|Win32.Build.0 = Debug|Win32 16 | {73A4A9B6-0981-4BBE-B452-41DFB0761D5C}.Release|Win32.ActiveCfg = Release|Win32 17 | {73A4A9B6-0981-4BBE-B452-41DFB0761D5C}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-9/3-9.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-9/3-9.v12.suo -------------------------------------------------------------------------------- /cpp11book/第三章/3-9/3-9/3-9.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /cpp11book/第三章/3-9/3-9/MyDLL.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-9/3-9/MyDLL.dll -------------------------------------------------------------------------------- /cpp11book/第三章/3-9/3-9/MyDLL.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" __declspec(dllexport) int Add(int &a,int &b); 4 | 5 | extern "C" __declspec(dllexport) int Max(const int &a, const int &b); 6 | extern "C" __declspec(dllexport) int Get(const int &a); -------------------------------------------------------------------------------- /cpp11book/第三章/3-9/3-9/MyDLL.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第三章/3-9/3-9/MyDLL.lib -------------------------------------------------------------------------------- /cpp11book/第三章/3-9/3-9/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "MyDLL.h" 2 | 3 | #include 4 | #include 5 | 6 | void TestDll() 7 | { 8 | typedef int(*pMax)(int a, int b); 9 | typedef int(*pGet)(int a); 10 | 11 | HINSTANCE hDLL = LoadLibrary("MyDll.dll"); 12 | if (hDLL == nullptr) 13 | { 14 | return; 15 | } 16 | 17 | pMax Max = (pMax)GetProcAddress(hDLL, "Max"); 18 | if (Max == nullptr) 19 | { 20 | return; 21 | } 22 | 23 | int ret = Max(5, 8); 24 | 25 | pGet Get = (pGet)GetProcAddress(hDLL, "Get"); 26 | if (Get == nullptr) 27 | { 28 | return; 29 | } 30 | 31 | int ret2 = Get(5); 32 | 33 | FreeLibrary(hDLL); 34 | } 35 | 36 | int main(void) 37 | { 38 | TestDll(); 39 | 40 | system("pause"); 41 | return 0; 42 | } -------------------------------------------------------------------------------- /cpp11book/第二章/2-1/2-1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "2-1", "2-1\2-1.vcxproj", "{37F1C6A5-79E1-4B33-91F9-2F2461D8253E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {37F1C6A5-79E1-4B33-91F9-2F2461D8253E}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {37F1C6A5-79E1-4B33-91F9-2F2461D8253E}.Debug|Win32.Build.0 = Debug|Win32 16 | {37F1C6A5-79E1-4B33-91F9-2F2461D8253E}.Release|Win32.ActiveCfg = Release|Win32 17 | {37F1C6A5-79E1-4B33-91F9-2F2461D8253E}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第二章/2-1/2-1.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第二章/2-1/2-1.v12.suo -------------------------------------------------------------------------------- /cpp11book/第二章/2-1/2-1/2-1.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第二章/2-1/2-1/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #ifndef _MSC_VER 7 | #include 8 | #endif 9 | 10 | template 11 | std::string type_name() 12 | { 13 | typedef typename std::remove_reference::type TR; 14 | std::unique_ptr own( 15 | #ifndef __GNUC__ 16 | nullptr, 17 | #else 18 | abi::__cxa_demangle(typeid(TR).name()), nullptr, 19 | nullptr, nullptr), 20 | #endif 21 | std::free); 22 | 23 | std::string r = own != nullptr ? own.get() : typeid(TR).name(); 24 | 25 | if (std::is_const::value) 26 | { 27 | r += " const"; 28 | } 29 | if (std::is_volatile::value) 30 | { 31 | r += " volatile"; 32 | } 33 | 34 | if (std::is_lvalue_reference::value) 35 | { 36 | r += "&"; 37 | } 38 | else if (std::is_rvalue_reference::value) 39 | { 40 | r += "&&"; 41 | } 42 | 43 | return r; 44 | } 45 | 46 | template 47 | void Func(T&& t) 48 | { 49 | std::cout << type_name() << std::endl; 50 | } 51 | 52 | int main(void) 53 | { 54 | std::string str = "Test"; 55 | Func(str); 56 | Func(std::move(str)); 57 | 58 | system("pause"); 59 | return 0; 60 | } -------------------------------------------------------------------------------- /cpp11book/第二章/2-2/2-2.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "2-2", "2-2\2-2.vcxproj", "{8B1E65F9-28A4-44C1-B149-F5FD73969169}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {8B1E65F9-28A4-44C1-B149-F5FD73969169}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {8B1E65F9-28A4-44C1-B149-F5FD73969169}.Debug|Win32.Build.0 = Debug|Win32 16 | {8B1E65F9-28A4-44C1-B149-F5FD73969169}.Release|Win32.ActiveCfg = Release|Win32 17 | {8B1E65F9-28A4-44C1-B149-F5FD73969169}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第二章/2-2/2-2.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第二章/2-2/2-2.v12.suo -------------------------------------------------------------------------------- /cpp11book/第二章/2-2/2-2/2-2.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第二章/2-2/2-2/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | class MyString 5 | { 6 | private: 7 | char* m_data; 8 | size_t m_len; 9 | void copy_data(const char* s) 10 | { 11 | m_data = new char[m_len + 1]; 12 | memcpy(m_data, s, m_len); 13 | m_data[m_len] = '\0'; 14 | } 15 | 16 | public: 17 | MyString() 18 | { 19 | m_data = NULL; 20 | m_len = 0; 21 | } 22 | 23 | MyString(const char* p) 24 | { 25 | m_len = strlen(p); 26 | copy_data(p); 27 | } 28 | 29 | MyString(const MyString& str) 30 | { 31 | m_len = str.m_len; 32 | copy_data(str.m_data); 33 | std::cout << "Copy Constructor is called! source:" << str.m_data << std::endl; 34 | } 35 | 36 | MyString& operator=(const MyString& str) 37 | { 38 | if (this != &str) 39 | { 40 | m_len = str.m_len; 41 | copy_data(str.m_data); 42 | } 43 | std::cout << "Copy Assignment is called! source:" << str.m_data << std::endl; 44 | return *this; 45 | } 46 | 47 | virtual ~MyString() 48 | { 49 | if (m_data != NULL) 50 | { 51 | delete[] m_data; 52 | } 53 | } 54 | }; 55 | 56 | int main(void) 57 | { 58 | MyString a; 59 | a = MyString("Hello"); 60 | 61 | std::vector vec; 62 | vec.push_back(MyString("World")); 63 | 64 | system("pause"); 65 | return 0; 66 | } -------------------------------------------------------------------------------- /cpp11book/第二章/2-3/2-3.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "2-3", "2-3\2-3.vcxproj", "{37F90758-212F-43F8-8736-0FDA68907827}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {37F90758-212F-43F8-8736-0FDA68907827}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {37F90758-212F-43F8-8736-0FDA68907827}.Debug|Win32.Build.0 = Debug|Win32 16 | {37F90758-212F-43F8-8736-0FDA68907827}.Release|Win32.ActiveCfg = Release|Win32 17 | {37F90758-212F-43F8-8736-0FDA68907827}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第二章/2-3/2-3.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第二章/2-3/2-3.v12.suo -------------------------------------------------------------------------------- /cpp11book/第二章/2-3/2-3/2-3.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第二章/2-4/2-4.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "2-4", "2-4\2-4.vcxproj", "{5BC2F337-7370-4C21-B61D-11814B6E1C81}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {5BC2F337-7370-4C21-B61D-11814B6E1C81}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {5BC2F337-7370-4C21-B61D-11814B6E1C81}.Debug|Win32.Build.0 = Debug|Win32 16 | {5BC2F337-7370-4C21-B61D-11814B6E1C81}.Release|Win32.ActiveCfg = Release|Win32 17 | {5BC2F337-7370-4C21-B61D-11814B6E1C81}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第二章/2-4/2-4.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第二章/2-4/2-4.v12.suo -------------------------------------------------------------------------------- /cpp11book/第二章/2-4/2-4/2-4.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第二章/2-4/2-4/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void PrintT(int& t) 4 | { 5 | std::cout << "lvalue" << std::endl; 6 | } 7 | 8 | template 9 | void PrintT(T&& t) 10 | { 11 | std::cout << "rvalue" << std::endl; 12 | } 13 | 14 | template 15 | void TestForward(T&& v) 16 | { 17 | PrintT(v); 18 | PrintT(std::forward(v)); 19 | PrintT(std::move(v)); 20 | } 21 | 22 | void Test() 23 | { 24 | TestForward(1); 25 | int x = 1; 26 | TestForward(x); 27 | TestForward(std::forward(x)); 28 | } 29 | 30 | int main(void) 31 | { 32 | Test(); 33 | 34 | system("pause"); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /cpp11book/第二章/2-5/2-5.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "2-5", "2-5\2-5.vcxproj", "{5B3B39C9-9871-4D3A-BA86-EF0DDE2486C2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {5B3B39C9-9871-4D3A-BA86-EF0DDE2486C2}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {5B3B39C9-9871-4D3A-BA86-EF0DDE2486C2}.Debug|Win32.Build.0 = Debug|Win32 16 | {5B3B39C9-9871-4D3A-BA86-EF0DDE2486C2}.Release|Win32.ActiveCfg = Release|Win32 17 | {5B3B39C9-9871-4D3A-BA86-EF0DDE2486C2}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第二章/2-5/2-5.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第二章/2-5/2-5.v12.suo -------------------------------------------------------------------------------- /cpp11book/第二章/2-5/2-5/2-5.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第二章/2-5/2-5/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | struct Complicated 9 | { 10 | int year; 11 | double country; 12 | string name; 13 | 14 | Complicated(int a, double b, string c) : year(a), country(b), name(c) 15 | { 16 | cout << "is constructed" << endl; 17 | } 18 | 19 | Complicated(const Complicated& other) : year(other.year), 20 | country(other.country), name(other.name) 21 | { 22 | cout << "is moved" << endl; 23 | } 24 | }; 25 | 26 | int main(void) 27 | { 28 | map m; 29 | int anInt = 4; 30 | double aDouble = 5.0; 31 | string aString = "C++"; 32 | 33 | cout << "--insert--" << endl; 34 | m.insert(make_pair(4, Complicated(anInt, aDouble, aString))); 35 | 36 | cout << "--emplace--" << endl; 37 | m.emplace(4, Complicated(anInt, aDouble, aString)); 38 | 39 | cout << "--emplace_back--" << endl; 40 | vector v; 41 | v.emplace_back(anInt, aDouble, aString); 42 | 43 | cout << "--push_back--" << endl; 44 | v.push_back(Complicated(anInt, aDouble, aString)); 45 | 46 | system("pause"); 47 | return 0; 48 | } -------------------------------------------------------------------------------- /cpp11book/第二章/2-6/2-6.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "2-6", "2-6\2-6.vcxproj", "{9FF2E59A-9C62-4C59-AFDD-BE520FBB1405}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {9FF2E59A-9C62-4C59-AFDD-BE520FBB1405}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {9FF2E59A-9C62-4C59-AFDD-BE520FBB1405}.Debug|Win32.Build.0 = Debug|Win32 16 | {9FF2E59A-9C62-4C59-AFDD-BE520FBB1405}.Release|Win32.ActiveCfg = Release|Win32 17 | {9FF2E59A-9C62-4C59-AFDD-BE520FBB1405}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第二章/2-6/2-6.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第二章/2-6/2-6.v12.suo -------------------------------------------------------------------------------- /cpp11book/第二章/2-6/2-6/2-6.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第二章/2-6/2-6/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | struct Key 9 | { 10 | std::string first; 11 | std::string second; 12 | }; 13 | 14 | struct KeyHash 15 | { 16 | std::size_t operator()(const Key& k) const 17 | { 18 | return std::hash()(k.first) ^ 19 | (std::hash()(k.second) << 1); 20 | } 21 | }; 22 | 23 | struct KeyEqual 24 | { 25 | bool operator()(const Key& lhs, const Key& rhs) const 26 | { 27 | return lhs.first == rhs.first && lhs.second == rhs.second; 28 | } 29 | }; 30 | 31 | int main(void) 32 | { 33 | std::unordered_map m1; 34 | std::unordered_map m2 = { { 1, "foo" }, { 2, "bar" }, { 3, "baz" } }; 35 | std::unordered_map m3 = m2; 36 | std::unordered_map m4 = std::move(m2); 37 | 38 | std::vector, int>> v = { { 0x12, 1 }, { 0x01, -1 } }; 39 | std::unordered_map, double> m5(v.begin(), v.end()); 40 | 41 | std::unordered_map m6 = 42 | { { { "John", "Doe" }, "example" }, { { "Mary", "Sue" }, "another" } }; 43 | 44 | system("pause"); 45 | return 0; 46 | } -------------------------------------------------------------------------------- /cpp11book/第二章/VC清理助手.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第二章/VC清理助手.bat -------------------------------------------------------------------------------- /cpp11book/第五章/5-1/5-1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "5-1", "5-1\5-1.vcxproj", "{3F31E00C-202E-46B0-AC95-D9790BE5F1D5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3F31E00C-202E-46B0-AC95-D9790BE5F1D5}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {3F31E00C-202E-46B0-AC95-D9790BE5F1D5}.Debug|Win32.Build.0 = Debug|Win32 16 | {3F31E00C-202E-46B0-AC95-D9790BE5F1D5}.Release|Win32.ActiveCfg = Release|Win32 17 | {3F31E00C-202E-46B0-AC95-D9790BE5F1D5}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-1/5-1.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第五章/5-1/5-1.v12.suo -------------------------------------------------------------------------------- /cpp11book/第五章/5-1/5-1/5-1.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-1/5-1/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | std::mutex g_lock; 7 | 8 | void func() 9 | { 10 | g_lock.lock(); 11 | 12 | std::cout << "entered thread " << std::this_thread::get_id() << std::endl; 13 | std::this_thread::sleep_for(std::chrono::seconds(1)); 14 | std::cout << "leaving thread " << std::this_thread::get_id() << std::endl; 15 | 16 | g_lock.unlock(); 17 | } 18 | 19 | int main(void) 20 | { 21 | std::thread t1(func); 22 | std::thread t2(func); 23 | std::thread t3(func); 24 | 25 | t1.join(); 26 | t2.join(); 27 | t3.join(); 28 | 29 | system("pause"); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /cpp11book/第五章/5-10/5-10.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "5-10", "5-10\5-10.vcxproj", "{65DDD0C5-DA94-46F3-AA7B-11F6A32246E9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {65DDD0C5-DA94-46F3-AA7B-11F6A32246E9}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {65DDD0C5-DA94-46F3-AA7B-11F6A32246E9}.Debug|Win32.Build.0 = Debug|Win32 16 | {65DDD0C5-DA94-46F3-AA7B-11F6A32246E9}.Release|Win32.ActiveCfg = Release|Win32 17 | {65DDD0C5-DA94-46F3-AA7B-11F6A32246E9}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-10/5-10.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第五章/5-10/5-10.v12.suo -------------------------------------------------------------------------------- /cpp11book/第五章/5-10/5-10/5-10.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-10/5-10/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void TestAsync() 5 | { 6 | std::future f1 = std::async(std::launch::async, [](){ 7 | return 8; 8 | }); 9 | 10 | std::cout << f1.get() << std::endl; //output: 8 11 | 12 | std::future f2 = std::async(std::launch::async, [](){ 13 | std::cout << 8 << std::endl; return; 14 | }); 15 | 16 | f2.wait(); //output: 8 17 | 18 | std::future future = std::async(std::launch::async, [](){ 19 | std::this_thread::sleep_for(std::chrono::seconds(3)); 20 | return 8; 21 | }); 22 | 23 | std::cout << "waiting...\n"; 24 | std::future_status status; 25 | 26 | do { 27 | status = future.wait_for(std::chrono::seconds(1)); 28 | 29 | if (status == std::future_status::deferred) 30 | { 31 | std::cout << "deferred\n"; 32 | } 33 | else if (status == std::future_status::timeout) 34 | { 35 | std::cout << "timeout\n"; 36 | } 37 | else if (status == std::future_status::ready) 38 | { 39 | std::cout << "ready!\n"; 40 | } 41 | } while (status != std::future_status::ready); 42 | 43 | std::cout << "result is " << future.get() << '\n'; 44 | } 45 | 46 | int main(void) 47 | { 48 | TestAsync(); 49 | 50 | system("pause"); 51 | return 0; 52 | } -------------------------------------------------------------------------------- /cpp11book/第五章/5-2/5-2.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "5-2", "5-2\5-2.vcxproj", "{9C4619B7-CAB8-4B4F-9324-F589707BF3B5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {9C4619B7-CAB8-4B4F-9324-F589707BF3B5}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {9C4619B7-CAB8-4B4F-9324-F589707BF3B5}.Debug|Win32.Build.0 = Debug|Win32 16 | {9C4619B7-CAB8-4B4F-9324-F589707BF3B5}.Release|Win32.ActiveCfg = Release|Win32 17 | {9C4619B7-CAB8-4B4F-9324-F589707BF3B5}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-2/5-2.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第五章/5-2/5-2.v12.suo -------------------------------------------------------------------------------- /cpp11book/第五章/5-2/5-2/5-2.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-2/5-2/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct Complex 6 | { 7 | std::mutex mutex; 8 | int i; 9 | 10 | Complex() : i(0){} 11 | 12 | void mul(int x) 13 | { 14 | std::lock_guard lock(mutex); 15 | i *= x; 16 | } 17 | 18 | void div(int x) 19 | { 20 | std::lock_guard lock(mutex); 21 | i /= x; 22 | } 23 | 24 | void both(int x, int y) 25 | { 26 | std::lock_guard lock(mutex); 27 | mul(x); 28 | div(y); 29 | } 30 | }; 31 | 32 | int main(void) 33 | { 34 | Complex complex; 35 | 36 | complex.both(32, 23); 37 | 38 | system("pause"); 39 | return 0; 40 | } -------------------------------------------------------------------------------- /cpp11book/第五章/5-3/5-3.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "5-3", "5-3\5-3.vcxproj", "{5B978689-BEE9-4B8A-8134-36618A178C7A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {5B978689-BEE9-4B8A-8134-36618A178C7A}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {5B978689-BEE9-4B8A-8134-36618A178C7A}.Debug|Win32.Build.0 = Debug|Win32 16 | {5B978689-BEE9-4B8A-8134-36618A178C7A}.Release|Win32.ActiveCfg = Release|Win32 17 | {5B978689-BEE9-4B8A-8134-36618A178C7A}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-3/5-3.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第五章/5-3/5-3.v12.suo -------------------------------------------------------------------------------- /cpp11book/第五章/5-3/5-3/5-3.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-3/5-3/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第五章/5-3/5-3/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第五章/5-4/5-4.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "5-4", "5-4\5-4.vcxproj", "{FC8452D7-E64F-43F6-9D1C-2EB3E2B6394C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {FC8452D7-E64F-43F6-9D1C-2EB3E2B6394C}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {FC8452D7-E64F-43F6-9D1C-2EB3E2B6394C}.Debug|Win32.Build.0 = Debug|Win32 16 | {FC8452D7-E64F-43F6-9D1C-2EB3E2B6394C}.Release|Win32.ActiveCfg = Release|Win32 17 | {FC8452D7-E64F-43F6-9D1C-2EB3E2B6394C}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-4/5-4.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第五章/5-4/5-4.v12.suo -------------------------------------------------------------------------------- /cpp11book/第五章/5-4/5-4/5-4.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-4/5-4/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | std::timed_mutex mutex; 7 | 8 | void work() 9 | { 10 | std::chrono::milliseconds timeout(100); 11 | 12 | while (true) 13 | { 14 | if (mutex.try_lock_for(timeout)) 15 | { 16 | std::cout << std::this_thread::get_id() << ": do work with the mutex" << std::endl; 17 | 18 | std::chrono::milliseconds sleepDuration(250); 19 | std::this_thread::sleep_for(sleepDuration); 20 | 21 | mutex.unlock(); 22 | std::this_thread::sleep_for(sleepDuration); 23 | } 24 | else 25 | { 26 | std::cout << std::this_thread::get_id() << ": do work without the mutex" << std::endl; 27 | 28 | std::chrono::milliseconds sleepDuration(100); 29 | std::this_thread::sleep_for(sleepDuration); 30 | } 31 | } 32 | } 33 | 34 | int main(void) 35 | { 36 | std::thread t1(work); 37 | std::thread t2(work); 38 | 39 | t1.join(); 40 | t2.join(); 41 | 42 | system("pause"); 43 | return 0; 44 | } -------------------------------------------------------------------------------- /cpp11book/第五章/5-5/5-5.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "5-5", "5-5\5-5.vcxproj", "{24B34022-291C-4DD8-9B27-A26169CC4C9E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {24B34022-291C-4DD8-9B27-A26169CC4C9E}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {24B34022-291C-4DD8-9B27-A26169CC4C9E}.Debug|Win32.Build.0 = Debug|Win32 16 | {24B34022-291C-4DD8-9B27-A26169CC4C9E}.Release|Win32.ActiveCfg = Release|Win32 17 | {24B34022-291C-4DD8-9B27-A26169CC4C9E}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-5/5-5.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第五章/5-5/5-5.v12.suo -------------------------------------------------------------------------------- /cpp11book/第五章/5-5/5-5/5-5.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-5/5-5/SyncQueue.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第五章/5-5/5-5/SyncQueue.hpp -------------------------------------------------------------------------------- /cpp11book/第五章/5-5/5-5/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "SyncQueue.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | SyncQueue syncQueue(5); 8 | 9 | void PutDatas() 10 | { 11 | for (int i = 0; i < 20; ++i) 12 | { 13 | syncQueue.Put(888); 14 | } 15 | } 16 | 17 | void TakeDatas() 18 | { 19 | int x = 0; 20 | 21 | for (int i = 0; i < 20; ++i) 22 | { 23 | syncQueue.Take(x); 24 | std::cout << x << std::endl; 25 | } 26 | } 27 | 28 | int main(void) 29 | { 30 | std::thread t1(PutDatas); 31 | std::thread t2(TakeDatas); 32 | 33 | t1.join(); 34 | t2.join(); 35 | 36 | system("pause"); 37 | return 0; 38 | } -------------------------------------------------------------------------------- /cpp11book/第五章/5-6/5-6.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "5-6", "5-6\5-6.vcxproj", "{6F59C29C-5674-4F86-9DE9-7FA6C289267B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {6F59C29C-5674-4F86-9DE9-7FA6C289267B}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {6F59C29C-5674-4F86-9DE9-7FA6C289267B}.Debug|Win32.Build.0 = Debug|Win32 16 | {6F59C29C-5674-4F86-9DE9-7FA6C289267B}.Release|Win32.ActiveCfg = Release|Win32 17 | {6F59C29C-5674-4F86-9DE9-7FA6C289267B}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-6/5-6.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第五章/5-6/5-6.v12.suo -------------------------------------------------------------------------------- /cpp11book/第五章/5-6/5-6/5-6.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 23 | 24 | 源文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-6/5-6/SimpleSyncQueue.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | template 10 | class SimpleSyncQueue 11 | { 12 | public: 13 | SimpleSyncQueue(){} 14 | 15 | void Put(const T& x) 16 | { 17 | std::lock_guard locker(m_mutex); 18 | m_queue.push_back(x); 19 | m_notEmpty.notify_one(); 20 | } 21 | 22 | void Take(T& x) 23 | { 24 | std::unique_lock locker(m_mutex); 25 | m_notEmpty.wait(locker, [this]{return !m_queue.empty(); }); 26 | x = m_queue.front(); 27 | m_queue.pop_front(); 28 | } 29 | 30 | bool Empty() 31 | { 32 | std::lock_guard locker(m_mutex); 33 | return m_queue.empty(); 34 | } 35 | 36 | size_t Size() 37 | { 38 | std::lock_guard locker(m_mutex); 39 | return m_queue.size(); 40 | } 41 | 42 | private: 43 | std::list m_queue; 44 | std::mutex m_mutex; 45 | std::condition_variable m_notEmpty; 46 | }; -------------------------------------------------------------------------------- /cpp11book/第五章/5-6/5-6/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "SimpleSyncQueue.hpp" 2 | 3 | #include 4 | #include 5 | 6 | SimpleSyncQueue syncQueue; 7 | 8 | void PutDatas() 9 | { 10 | for (int i = 0; i < 20; ++i) 11 | { 12 | syncQueue.Put(888); 13 | } 14 | } 15 | 16 | void TakeDatas() 17 | { 18 | int x = 0; 19 | 20 | for (int i = 0; i < 20; ++i) 21 | { 22 | syncQueue.Take(x); 23 | std::cout << x << std::endl; 24 | } 25 | } 26 | 27 | int main(void) 28 | { 29 | std::thread t1(PutDatas); 30 | std::thread t2(TakeDatas); 31 | 32 | t1.join(); 33 | t2.join(); 34 | 35 | system("pause"); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /cpp11book/第五章/5-7/5-7.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "5-7", "5-7\5-7.vcxproj", "{5B72D6A3-2223-47E6-AC2D-49980A037EA2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {5B72D6A3-2223-47E6-AC2D-49980A037EA2}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {5B72D6A3-2223-47E6-AC2D-49980A037EA2}.Debug|Win32.Build.0 = Debug|Win32 16 | {5B72D6A3-2223-47E6-AC2D-49980A037EA2}.Release|Win32.ActiveCfg = Release|Win32 17 | {5B72D6A3-2223-47E6-AC2D-49980A037EA2}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-7/5-7.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第五章/5-7/5-7.v12.suo -------------------------------------------------------------------------------- /cpp11book/第五章/5-7/5-7/5-7.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-7/5-7/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct Counter 6 | { 7 | int value = 0; 8 | std::mutex mutex; 9 | 10 | void increment() 11 | { 12 | std::lock_guard lock(mutex); 13 | ++value; 14 | std::cout << value << std::endl; 15 | } 16 | 17 | void decrement() 18 | { 19 | std::lock_guard lock(mutex); 20 | --value; 21 | std::cout << value << std::endl; 22 | } 23 | 24 | int get() 25 | { 26 | return value; 27 | } 28 | }; 29 | 30 | Counter g_counter; 31 | 32 | void Increments() 33 | { 34 | for (int i = 0; i < 10; ++i) 35 | { 36 | g_counter.increment(); 37 | } 38 | } 39 | 40 | void Decrements() 41 | { 42 | for (int i = 0; i < 5; ++i) 43 | { 44 | g_counter.decrement(); 45 | } 46 | } 47 | 48 | int main(void) 49 | { 50 | std::thread t1(Increments); 51 | std::thread t2(Decrements); 52 | 53 | t1.join(); 54 | t2.join(); 55 | 56 | system("pause"); 57 | return 0; 58 | } -------------------------------------------------------------------------------- /cpp11book/第五章/5-8/5-8.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "5-8", "5-8\5-8.vcxproj", "{6FC31014-378B-4F0B-9389-A53E0316B809}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {6FC31014-378B-4F0B-9389-A53E0316B809}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {6FC31014-378B-4F0B-9389-A53E0316B809}.Debug|Win32.Build.0 = Debug|Win32 16 | {6FC31014-378B-4F0B-9389-A53E0316B809}.Release|Win32.ActiveCfg = Release|Win32 17 | {6FC31014-378B-4F0B-9389-A53E0316B809}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-8/5-8.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第五章/5-8/5-8.v12.suo -------------------------------------------------------------------------------- /cpp11book/第五章/5-8/5-8/5-8.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-8/5-8/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct Counter 6 | { 7 | std::atomic value = 0; 8 | 9 | void increment() 10 | { 11 | ++value; 12 | } 13 | 14 | void decrement() 15 | { 16 | --value; 17 | } 18 | 19 | int get() 20 | { 21 | return value; 22 | } 23 | }; 24 | 25 | Counter g_counter; 26 | 27 | void Increments() 28 | { 29 | for (int i = 0; i < 10; ++i) 30 | { 31 | g_counter.increment(); 32 | std::cout << g_counter.get() << std::endl; 33 | } 34 | } 35 | 36 | void Decrements() 37 | { 38 | for (int i = 0; i < 5; ++i) 39 | { 40 | g_counter.decrement(); 41 | std::cout << g_counter.get() << std::endl; 42 | } 43 | } 44 | 45 | int main(void) 46 | { 47 | std::thread t1(Increments); 48 | std::thread t2(Decrements); 49 | 50 | t1.join(); 51 | t2.join(); 52 | 53 | system("pause"); 54 | return 0; 55 | } -------------------------------------------------------------------------------- /cpp11book/第五章/5-9/5-9.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "5-9", "5-9\5-9.vcxproj", "{D06D2AD5-0363-4128-9B95-9B233CAA146C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D06D2AD5-0363-4128-9B95-9B233CAA146C}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {D06D2AD5-0363-4128-9B95-9B233CAA146C}.Debug|Win32.Build.0 = Debug|Win32 16 | {D06D2AD5-0363-4128-9B95-9B233CAA146C}.Release|Win32.ActiveCfg = Release|Win32 17 | {D06D2AD5-0363-4128-9B95-9B233CAA146C}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-9/5-9.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第五章/5-9/5-9.v12.suo -------------------------------------------------------------------------------- /cpp11book/第五章/5-9/5-9/5-9.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第五章/5-9/5-9/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第五章/5-9/5-9/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第六章/6-1/6-1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "6-1", "6-1\6-1.vcxproj", "{F9AE37F0-5F93-4F5C-9D3C-FE1708FC4853}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {F9AE37F0-5F93-4F5C-9D3C-FE1708FC4853}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {F9AE37F0-5F93-4F5C-9D3C-FE1708FC4853}.Debug|Win32.Build.0 = Debug|Win32 16 | {F9AE37F0-5F93-4F5C-9D3C-FE1708FC4853}.Release|Win32.ActiveCfg = Release|Win32 17 | {F9AE37F0-5F93-4F5C-9D3C-FE1708FC4853}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第六章/6-1/6-1.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第六章/6-1/6-1.v12.suo -------------------------------------------------------------------------------- /cpp11book/第六章/6-1/6-1/6-1.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 23 | 24 | 源文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /cpp11book/第六章/6-1/6-1/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第六章/6-1/6-1/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第六章/6-1/6-1/Timer.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第六章/6-1/6-1/Timer.hpp -------------------------------------------------------------------------------- /cpp11book/第六章/6-2/6-2.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "6-2", "6-2\6-2.vcxproj", "{46A17B43-0FCD-4F36-BE31-CEF5E83D2008}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {46A17B43-0FCD-4F36-BE31-CEF5E83D2008}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {46A17B43-0FCD-4F36-BE31-CEF5E83D2008}.Debug|Win32.Build.0 = Debug|Win32 16 | {46A17B43-0FCD-4F36-BE31-CEF5E83D2008}.Release|Win32.ActiveCfg = Release|Win32 17 | {46A17B43-0FCD-4F36-BE31-CEF5E83D2008}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第六章/6-2/6-2.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第六章/6-2/6-2.v12.suo -------------------------------------------------------------------------------- /cpp11book/第六章/6-2/6-2/6-2.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第六章/6-2/6-2/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | double f = 1.53; 7 | std::string f_str = std::to_string(f); 8 | std::cout << f_str << std::endl; 9 | 10 | double f1 = 4.125; 11 | std::wstring f_str1 = std::to_wstring(f1); 12 | std::wcout << f_str1 << std::endl; 13 | 14 | const char* str1 = "10"; 15 | const char* str2 = "3.1415926"; 16 | const char* str3 = "31337 with words"; 17 | const char* str4 = "words and 2"; 18 | 19 | int num1 = std::atoi(str1); 20 | int num2 = std::atoi(str2); 21 | int num3 = std::atoi(str3); 22 | int num4 = std::atoi(str4); 23 | double f2 = std::atof(str2); 24 | 25 | std::cout << "std::atoi(\"" << str1 << "\") is " << num1 << '\n'; 26 | std::cout << "std::atoi(\"" << str2 << "\") is " << num2 << '\n'; 27 | std::cout << "std::atoi(\"" << str3 << "\") is " << num3 << '\n'; 28 | std::cout << "std::atoi(\"" << str4 << "\") is " << num4 << '\n'; 29 | std::cout << "std::atoi(\"" << str2 << "\") is " << f2 << std::endl; 30 | 31 | system("pause"); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /cpp11book/第六章/6-3/6-3.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "6-3", "6-3\6-3.vcxproj", "{C9117DC2-04BC-41FF-9E25-0F4BE29138DB}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C9117DC2-04BC-41FF-9E25-0F4BE29138DB}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {C9117DC2-04BC-41FF-9E25-0F4BE29138DB}.Debug|Win32.Build.0 = Debug|Win32 16 | {C9117DC2-04BC-41FF-9E25-0F4BE29138DB}.Release|Win32.ActiveCfg = Release|Win32 17 | {C9117DC2-04BC-41FF-9E25-0F4BE29138DB}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第六章/6-3/6-3.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第六章/6-3/6-3.v12.suo -------------------------------------------------------------------------------- /cpp11book/第六章/6-3/6-3/6-3.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第六章/6-3/6-3/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第六章/6-3/6-3/Test.cpp -------------------------------------------------------------------------------- /cpp11book/第六章/VC清理助手.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第六章/VC清理助手.bat -------------------------------------------------------------------------------- /cpp11book/第四章/4-1/4-1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "4-1", "4-1\4-1.vcxproj", "{2725E2F4-4699-4C68-B231-5CBF5EF39E5C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {2725E2F4-4699-4C68-B231-5CBF5EF39E5C}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {2725E2F4-4699-4C68-B231-5CBF5EF39E5C}.Debug|Win32.Build.0 = Debug|Win32 16 | {2725E2F4-4699-4C68-B231-5CBF5EF39E5C}.Release|Win32.ActiveCfg = Release|Win32 17 | {2725E2F4-4699-4C68-B231-5CBF5EF39E5C}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /cpp11book/第四章/4-1/4-1.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第四章/4-1/4-1.v12.suo -------------------------------------------------------------------------------- /cpp11book/第四章/4-1/4-1/4-1.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpp11book/第四章/4-1/4-1/Test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qicosmos/cosmos/7dc9c2f9ce574ac06a78e2e7ab54eb301259ad62/cpp11book/第四章/4-1/4-1/Test.cpp -------------------------------------------------------------------------------- /pattern/Command.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | template 4 | struct CommCommand 5 | { 6 | private: 7 | std::function < Ret()> m_f; 8 | 9 | public: 10 | //接受可调用对象的函数包装器 11 | template< class F, class... Args, class = typename std::enable_if::value>::type> 12 | void Wrap(F && f, Args && ... args) 13 | { 14 | m_f = [&]{return f(args...); }; 15 | } 16 | 17 | //接受常量成员函数的函数包装器 18 | template 19 | void Wrap(R(C::*f)(DArgs...) const, P && p, Args && ... args) 20 | { 21 | m_f = [&, f]{return (*p.*f)(args...); }; 22 | } 23 | 24 | //接受非常量成员函数的函数包装器 25 | template 26 | void Wrap(R(C::*f)(DArgs...), P && p, Args && ... args) 27 | { 28 | m_f = [&, f]{return (*p.*f)(args...); }; 29 | } 30 | 31 | Ret Excecute() 32 | { 33 | return m_f(); 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /pattern/ObjectPool.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "NonCopyable.hpp" 6 | using namespace std; 7 | 8 | const int MaxObjectNum = 10; 9 | 10 | template 11 | class ObjectPool : NonCopyable 12 | { 13 | template 14 | using Constructor = std::function(Args...)>; 15 | public: 16 | //默认创建多少个对象 17 | template 18 | void Init(size_t num, Args&&... args) 19 | { 20 | if (num<= 0 || num> MaxObjectNum) 21 | throw std::logic_error("object num out of range."); 22 | 23 | auto constructName = typeid(Constructor).name(); //不区分引用 24 | for (size_t i = 0; i (new T(std::forward(args)...), [this, constructName](T* p) //删除器中不直接删除对象,而是回收到对象池中,以供下次使用 27 | { 28 | m_object_map.emplace(std::move(constructName), std::shared_ptr(p)); 29 | })); 30 | } 31 | } 32 | 33 | //从对象池中获取一个对象 34 | template 35 | std::shared_ptr Get() 36 | { 37 | string constructName = typeid(Constructor).name(); 38 | 39 | auto range = m_object_map.equal_range(constructName); 40 | for (auto it = range.first; it != range.second; ++it) 41 | { 42 | auto ptr = it->second; 43 | m_object_map.erase(it); 44 | return ptr; 45 | } 46 | 47 | return nullptr; 48 | } 49 | 50 | private: 51 | multimap> m_object_map; 52 | }; 53 | -------------------------------------------------------------------------------- /pattern/Observer.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | #include "NonCopyable.hpp" 8 | 9 | template 10 | class Events : NonCopyable 11 | { 12 | public: 13 | //注册观察者,支持右值引用 14 | int Connect(Func&& f) 15 | { 16 | return Assgin(f); 17 | } 18 | 19 | //注册观察者 20 | int Connect(const Func& f) 21 | { 22 | return Assgin(f); 23 | } 24 | //移除观察者 25 | void Disconnect(int key) 26 | { 27 | m_connections.erase(key); 28 | } 29 | 30 | //通知所有的观察者 31 | template 32 | void Notify(Args&&... args) 33 | { 34 | for (auto& it: m_connections) 35 | { 36 | it.second(std::forward(args)...); 37 | } 38 | } 39 | 40 | private: 41 | //保存观察者并分配观察者的编号 42 | template 43 | int Assgin(F&& f) 44 | { 45 | int k=m_observerId++; 46 | m_connections.emplace(k, std::forward(f)); 47 | return k; 48 | } 49 | 50 | int m_observerId=0;//观察者对应的编号 51 | std::map m_connections;//观察者列表 52 | }; 53 | -------------------------------------------------------------------------------- /pattern/Singleton.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | template 4 | class Singleton 5 | { 6 | public: 7 | template 8 |   static T* Instance(Args&&... args) 9 |   { 10 | if(m_pInstance==nullptr) 11 | m_pInstance = new T(std::forward(args)...); 12 | 13 | return m_pInstance; 14 | } 15 | 16 |   static T* GetInstance() 17 |   { 18 |     if (m_pInstance == nullptr) 19 |       throw std::logic_error("the instance is not init, please initialize the instance first"); 20 | 21 |     return m_pInstance; 22 |   } 23 | 24 | static void DestroyInstance() 25 | { 26 | delete m_pInstance; 27 | m_pInstance = nullptr; 28 | } 29 | 30 | private: 31 | Singleton(void); 32 | virtual ~Singleton(void); 33 | Singleton(const Singleton&); 34 | Singleton& operator=(const Singleton&); 35 | private: 36 | static T* m_pInstance; 37 | }; 38 | 39 | template T* Singleton::m_pInstance = nullptr; 40 | -------------------------------------------------------------------------------- /pattern/Visitor.hpp: -------------------------------------------------------------------------------- 1 | template 2 | struct Visitor; 3 | 4 | template 5 | struct Visitor : Visitor 6 | { 7 | using Visitor::Visit;//通过using避免隐藏基类的visit同名方法 8 | virtual void Visit(const T&) = 0; 9 | }; 10 | 11 | template 12 | struct Visitor 13 | { 14 | virtual void Visit(const T&) = 0; 15 | }; 16 | -------------------------------------------------------------------------------- /self-register-factory/Message.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class Message 5 | { 6 | public: 7 | virtual ~Message() {} 8 | 9 | virtual void foo() 10 | { 11 | 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /self-register-factory/Message1.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MsgFactory.hpp" 4 | #include "Message.hpp" 5 | 6 | class Message1 : public Message 7 | { 8 | public: 9 | 10 | Message1() 11 | { 12 | std::cout << "message1" << std::endl; 13 | } 14 | 15 | Message1(int a) 16 | { 17 | std::cout << "message1" << std::endl; 18 | } 19 | 20 | ~Message1() 21 | { 22 | } 23 | 24 | void foo() override 25 | { 26 | std::cout << "message1" << std::endl; 27 | } 28 | }; 29 | 30 | //REGISTER_MESSAGE(Message1, "message1", 2); 31 | REGISTER_MESSAGE(Message1, "message1"); 32 | -------------------------------------------------------------------------------- /self-register-factory/MessageFactory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "Message.hpp" 7 | 8 | /* 9 | you can change the key type as integer. 10 | */ 11 | struct factory 12 | { 13 | template 14 | struct register_t 15 | { 16 | register_t(const std::string& key) 17 | { 18 | factory::get().map_.emplace(key, [] { return new T(); }); 19 | } 20 | 21 | template 22 | register_t(const std::string& key, Args... args) 23 | { 24 | factory::get().map_.emplace(key, [&] { return new T(args...); }); 25 | } 26 | }; 27 | 28 | static Message* produce(const std::string& key) 29 | { 30 | if (map_.find(key) == map_.end()) 31 | throw std::invalid_argument("the message key is not exist!"); 32 | 33 | return map_[key](); 34 | } 35 | 36 | static std::unique_ptr produce_unique(const std::string& key) 37 | { 38 | return std::unique_ptr(produce(key)); 39 | } 40 | 41 | static std::shared_ptr produce_shared(const std::string& key) 42 | { 43 | return std::shared_ptr(produce(key)); 44 | } 45 | 46 | private: 47 | factory() {}; 48 | factory(const factory&) = delete; 49 | factory(factory&&) = delete; 50 | 51 | static factory& get() 52 | { 53 | static factory instance; 54 | return instance; 55 | } 56 | 57 | static std::map> map_; 58 | }; 59 | 60 | std::map> factory::map_; 61 | 62 | #define REGISTER_MESSAGE_VNAME(T) reg_msg_##T##_ 63 | #define REGISTER_MESSAGE(T, key, ...) static factory::register_t REGISTER_MESSAGE_VNAME(T)(key, ##__VA_ARGS__); 64 | -------------------------------------------------------------------------------- /self-register-factory/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Message1.hpp" 2 | #include "Message2.hpp" 3 | 4 | int main() 5 | { 6 | Message* p = factory::produce("message1"); 7 | p->foo(); //Message1 8 | delete p; 9 | 10 | auto p2 = factory::produce_unique("message1"); 11 | p2->foo(); 12 | } 13 | -------------------------------------------------------------------------------- /tuple/TpForeach.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "TpIndexs.hpp" 3 | 4 | namespace details { 5 | 6 | template 7 | void for_each_impl(Func&& f, Last&& last) 8 | { 9 | f(std::forward(last)); 10 | } 11 | 12 | template 13 | void for_each_impl(Func&& f, First&& first, Rest&&...rest) 14 | { 15 | f(std::forward(first)); 16 | for_each_impl(std::forward(f), rest...); 17 | } 18 | 19 | template 20 | void for_each_helper(Func&& f, IndexTuple, std::tuple&& tup) 21 | { 22 | for_each_impl(std::forward(f), std::forward(std::get(tup))...); 23 | } 24 | 25 | } // namespace details 26 | 27 | template 28 | void tp_for_each(Func&& f, std::tuple& tup) 29 | { 30 | using namespace details; 31 | for_each_helper(forward(f), typename make_indexes::type(), std::tuple(tup)); 32 | } 33 | 34 | template 35 | void tp_for_each(Func&& f, std::tuple&& tup) 36 | { 37 | using namespace details; 38 | for_each_helper(forward(f), typename make_indexes::type(), forward>(tup)); 39 | } 40 | -------------------------------------------------------------------------------- /tuple/TpZip.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | using std::tuple; 6 | #include "TpIndexs.hpp" 7 | 8 | //将两个tuple合起来,前一个tuple中的每个元素为key,后一个tuple中的每个元素为value,组成一个pair集合 9 | namespace details 10 | { 11 | template 12 | using pair_type = std::pair::type, typename std::tuple_element::type>; 13 | 14 | template 15 | pair_type pair(const T1& tup1, const T2& tup2) 16 | { 17 | // 18 | return std::make_pair(std::get(tup1), std::get(tup2)); 19 | } 20 | 21 | template 22 | auto pairs_helper(IndexTuple, const T1& tup1, const T2& tup2) -> decltype(std::make_tuple(pair(tup1, tup2)...)) 23 | { 24 | return std::make_tuple(pair(tup1, tup2)...); 25 | } 26 | 27 | } // namespace details 28 | 29 | template 30 | auto Pairs(const std::tuple& tup1, const std::tuple& tup2) -> decltype(details::pairs_helper(typename make_indexes::type(), tup1, tup2)) 31 | { 32 | static_assert(sizeof... (Args1) == sizeof... (Args2), "tuples should be the same size."); 33 | return details::pairs_helper(typename make_indexes::type(), tup1, tup2); 34 | } 35 | -------------------------------------------------------------------------------- /type_name.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #ifndef _MSC_VER 5 | #include 6 | #endif 7 | #include 8 | #include 9 | #include 10 | 11 | //获取类型易读的名称 12 | template 13 | std::string type_name() 14 | { 15 | typedef typename std::remove_reference::type TR; 16 | std::unique_ptr own 17 | ( 18 | #ifndef __GNUC__ 19 | nullptr, 20 | #else 21 | abi::__cxa_demangle(typeid(TR).name(), nullptr, 22 | nullptr, nullptr), 23 | #endif 24 | std::free 25 | ); 26 | std::string r = own != nullptr ? own.get() : typeid(TR).name(); 27 | if (std::is_const::value) 28 | r += " const"; 29 | if (std::is_volatile::value) 30 | r += " volatile"; 31 | if (std::is_lvalue_reference::value) 32 | r += "&"; 33 | else if (std::is_rvalue_reference::value) 34 | r += "&&"; 35 | return r; 36 | } 37 | -------------------------------------------------------------------------------- /worksteal/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "thread_pool.hpp" 4 | 5 | void test_pool() 6 | { 7 | thread_pool pool; 8 | for(size_t i = 0; i < 1000; i++) 9 | { 10 | pool.add_task([]{ 11 | std::this_thread::sleep_for(std::chrono::microseconds(50)); 12 | }); 13 | } 14 | 15 | std::string s; 16 | std::cin>>s; 17 | 18 | } 19 | 20 | int main() 21 | { 22 | test_pool(); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /worksteal/sync_deque.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | template 6 | class sync_deque final 7 | { 8 | public: 9 | sync_deque() = default; 10 | ~sync_deque() = default; 11 | 12 | //LIFO 13 | void push_front(const T &val) 14 | { 15 | std::unique_lock l(mtx_); 16 | deque_.push_front(val); 17 | } 18 | 19 | T pop_front() 20 | { 21 | mtx_.lock(); 22 | 23 | if (deque_.empty()) 24 | { 25 | mtx_.unlock(); 26 | return nullptr; 27 | } 28 | 29 | T val = deque_.front(); 30 | deque_.pop_front(); 31 | 32 | mtx_.unlock(); 33 | 34 | return val; 35 | } 36 | 37 | //for steal FIFO 38 | T pop_back() 39 | { 40 | if (!mtx_.try_lock()) 41 | return nullptr; 42 | 43 | if (deque_.empty()) 44 | { 45 | mtx_.unlock(); 46 | return nullptr; 47 | } 48 | 49 | T val = deque_.back(); 50 | deque_.pop_back(); 51 | 52 | mtx_.unlock(); 53 | 54 | return val; 55 | } 56 | 57 | bool empty() 58 | { 59 | //std::unique_lock l(mtx_); 60 | return deque_.empty(); 61 | } 62 | 63 | private: 64 | std::deque deque_; 65 | std::mutex mtx_; 66 | }; 67 | 68 | -------------------------------------------------------------------------------- /worksteal/thread_pool.hpp: -------------------------------------------------------------------------------- 1 | #include "worker.hpp" 2 | 3 | class thread_pool 4 | { 5 | public: 6 | 7 | thread_pool(size_t thread_num = std::thread::hardware_concurrency()) 8 | { 9 | workers_ = std::make_shared>>(); 10 | for (size_t i = 0; i < thread_num; i++) 11 | { 12 | auto worker = std::make_shared(workers_, thread_num); 13 | workers_->push_back(worker); 14 | } 15 | } 16 | 17 | ~thread_pool() 18 | { 19 | for (auto worker : *workers_) 20 | { 21 | worker->join(); 22 | } 23 | 24 | workers_->clear(); 25 | } 26 | 27 | void add_task(const task_t& task) 28 | { 29 | auto worker = get_rand_worker(); 30 | worker->assign(task); 31 | } 32 | 33 | private: 34 | std::shared_ptr get_rand_worker() 35 | { 36 | int i = rand() % workers_->size(); 37 | return workers_->at(i); 38 | } 39 | 40 | workers_ptr workers_; 41 | }; 42 | --------------------------------------------------------------------------------