├── .gitignore ├── README.md ├── src ├── tlist.hpp └── tutils.hpp └── test ├── r0 ├── r0.cpp ├── r0.inf ├── r0.vcxproj └── r0.vcxproj.filters ├── r3 ├── r3.cpp ├── r3.vcxproj ├── r3.vcxproj.filters └── r3.vcxproj.user ├── test.hpp └── test.sln /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | test/bin64/ 34 | test/.vs/ 35 | test/r0/x64/ 36 | test/r3/x64/ 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tstl 2 | The kernel mode Standard Template Library Template 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | #### 如何使用 13 | 1. 包含`Tstl/src/` 14 | > 其中`tlist.hpp`是一个示例容器 15 | 2. 开启`c++17`支持 16 | 3. 自己实现你需要的容器, 比如`vector`、`array`、`map`... 17 | 18 | 19 | #### 其它 20 | - 不支持继承 21 | - 不支持虚函数 22 | 23 | > 以上缺失特性都可以使用`模板元编程`解决 24 | 25 | 26 | #### 相关 27 | 1. [驱动使用c++以及stl库](https://mp.weixin.qq.com/s/zazSyjOfB4un4SSB6XTVLQ) 28 | -------------------------------------------------------------------------------- /src/tlist.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _TLIST_HPP_ 2 | #define _TLIST_HPP_ 3 | #include "tutils.hpp" 4 | 5 | namespace Tstl { 6 | template 7 | class TList { 8 | private: 9 | typedef struct _Node { 10 | T Value; 11 | _Node* prevNode; 12 | _Node* nextNode; 13 | } Node, *PNode; 14 | 15 | public: 16 | TList() = default; 17 | ~TList() { 18 | clear(); 19 | } 20 | void _destory() { 21 | m_isDestory = true; 22 | clear(); 23 | } 24 | 25 | public: 26 | decltype(auto) add(T&& newData) { 27 | _add(Tstl::move(newData)); 28 | } 29 | decltype(auto) add(const T& newData) { 30 | _add(newData); 31 | } 32 | 33 | decltype(auto) remove(T targetData) { 34 | if (m_pHeadNode == nullptr) { 35 | return false; 36 | } 37 | 38 | auto temp = m_pHeadNode; 39 | 40 | if (temp->nextNode == nullptr) { 41 | if (temp->Value == targetData) { 42 | Tstl::del_mem(temp); 43 | m_pHeadNode = nullptr; 44 | return true; 45 | } else { 46 | return false; 47 | } 48 | } else { 49 | if (temp->Value == targetData) { 50 | temp->nextNode->prevNode = nullptr; 51 | m_pHeadNode = temp->nextNode; 52 | Tstl::del_mem(temp); 53 | return true; 54 | } 55 | } 56 | 57 | while (temp->nextNode != nullptr) { 58 | temp = temp->nextNode; 59 | if (temp->nextNode == nullptr) { 60 | if (temp->Value == targetData) { 61 | temp->prevNode->nextNode = nullptr; 62 | break; 63 | } else { 64 | return false; 65 | } 66 | } 67 | 68 | if (temp->Value == targetData) { 69 | temp->prevNode->nextNode = temp->nextNode; 70 | temp->nextNode->prevNode = temp->prevNode; 71 | break; 72 | } 73 | } 74 | Tstl::del_mem(temp); 75 | return true; 76 | } 77 | 78 | decltype(auto) clear() { 79 | if (m_pHeadNode == nullptr) { 80 | return; 81 | } 82 | auto temp = reinterpret_cast(0); 83 | for (auto cur = m_pHeadNode; cur != nullptr; cur = temp) { 84 | if constexpr (Tstl::is_class::value == true) { 85 | cur->Value._destory(); 86 | } 87 | temp = cur->nextNode; 88 | Tstl::del_mem(cur); 89 | } 90 | m_pHeadNode = nullptr; 91 | } 92 | 93 | template 94 | decltype(auto) _add(_Type&&... newValue) { 95 | auto pNewNode = Tstl::new_mem(); 96 | pNewNode->Value = T(Tstl::forward<_Type>(newValue)...); 97 | pNewNode->nextNode = m_pHeadNode; 98 | pNewNode->prevNode = nullptr; 99 | if (m_pHeadNode != nullptr) { 100 | m_pHeadNode->prevNode = pNewNode; 101 | } 102 | m_pHeadNode = pNewNode; 103 | } 104 | 105 | private: 106 | bool m_isDestory = false; 107 | PNode m_pHeadNode = nullptr; 108 | }; 109 | 110 | } // namespace Tstl 111 | 112 | #endif // !_TLIST_HPP_ -------------------------------------------------------------------------------- /src/tutils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _TUTILS_H_HPP_ 2 | #define _TUTILS_H_HPP_ 3 | #ifdef _KERNEL_TSTL 4 | #include 5 | #define _noexcept 6 | #else 7 | #define _noexcept noexcept 8 | #endif // _KERNEL_TSTL 9 | 10 | #if _HAS_NODISCARD 11 | #define _NODISCARD [[nodiscard]] 12 | #define _NODISCARD_PERF 13 | #else /* ^^^ CAN HAZ [[nodiscard]] ^^^ // vvv NO CAN HAZ [[nodiscard]] vvv */ 14 | #define _NODISCARD 15 | #define _NODISCARD_PERF 16 | #endif /* _HAS_NODISCARD */ 17 | 18 | #if _HAS_CXX17 19 | #define _INLINE_VAR inline 20 | #else /* _HAS_CXX17 */ 21 | #define _INLINE_VAR 22 | #endif /* _HAS_CXX17 */ 23 | 24 | #define _EMPTY_ARGUMENT 25 | #define _CLASS_DEFINE_CV(CLASS) \ 26 | CLASS(_EMPTY_ARGUMENT) \ 27 | CLASS(const) \ 28 | CLASS(volatile) \ 29 | CLASS(const volatile) 30 | 31 | namespace Tstl { 32 | template 33 | struct remove_pointer { 34 | using type = _Type; 35 | }; 36 | 37 | /**/ #define _REMOVE_POINTER(CV_OPT) /**/ template 38 | /**/ struct remove_pointer <_Type * CV_OPT> /**/ { /* remove pointer */ 39 | using type = _Type; /**/ 40 | }; 41 | _CLASS_DEFINE_CV(_REMOVE_POINTER) 42 | #undef _REMOVE_POINTER 43 | 44 | template 45 | using remove_pointer_t = typename remove_pointer<_Type>::type; 46 | 47 | template 48 | struct integral_constant { 49 | static constexpr _Type value = _Val; 50 | 51 | using value_type = _Type; 52 | using type = integral_constant; 53 | 54 | constexpr operator value_type() const noexcept { 55 | return (value); 56 | } 57 | 58 | _NODISCARD constexpr value_type operator()() const noexcept { 59 | return (value); 60 | } 61 | }; 62 | 63 | template 64 | using bool_constant = integral_constant; 65 | 66 | using true_type = bool_constant; 67 | using false_type = bool_constant; 68 | 69 | template 70 | struct is_class : bool_constant<__is_class(_Type)> {}; 71 | 72 | template 73 | struct is_lvalue_reference : false_type {}; 74 | 75 | template 76 | struct is_lvalue_reference<_Type&> : true_type {}; 77 | 78 | template 79 | _INLINE_VAR constexpr bool is_lvalue_reference_v = is_lvalue_reference<_Type>::value; 80 | 81 | template 82 | struct remove_reference { 83 | using type = _Type; 84 | }; 85 | 86 | template 87 | struct remove_reference<_Type&> { 88 | using type = _Type; 89 | }; 90 | 91 | template 92 | struct remove_reference<_Type&&> { 93 | using type = _Type; 94 | }; 95 | 96 | template 97 | using remove_reference_t = typename remove_reference<_Type>::type; 98 | 99 | template 100 | _NODISCARD constexpr _Type&& forward(remove_reference_t<_Type>& _Arg) _noexcept { 101 | return (static_cast<_Type&&>(_Arg)); 102 | } 103 | 104 | template 105 | _NODISCARD constexpr _Type&& forward(remove_reference_t<_Type>&& _Arg) _noexcept { 106 | static_assert(!is_lvalue_reference_v<_Type>, "bad forward call"); 107 | return (static_cast<_Type&&>(_Arg)); 108 | } 109 | 110 | template 111 | _NODISCARD constexpr remove_reference_t<_Type>&& move(_Type&& _Arg) _noexcept { 112 | return (static_cast&&>(_Arg)); 113 | } 114 | 115 | template 116 | _NODISCARD constexpr decltype(auto) new_mem() { 117 | void* ptr = nullptr; 118 | constexpr auto numberOfBytes = sizeof(_Type); 119 | #ifdef _KERNEL_TSTL 120 | ptr = ExAllocatePoolWithTag(NonPagedPoolExecute, numberOfBytes, 'Tstl'); 121 | #else 122 | ptr = malloc(numberOfBytes); 123 | #endif // _KERNEL_TSTL 124 | memset(ptr, 0, numberOfBytes); 125 | return reinterpret_cast<_Type*>(ptr); 126 | } 127 | 128 | inline decltype(auto) del_mem(void* ptr) { 129 | if (ptr == nullptr) { 130 | __debugbreak(); 131 | } 132 | #ifdef _KERNEL_TSTL 133 | ExFreePoolWithTag(ptr, 'Tstl'); 134 | #else 135 | free(ptr); 136 | #endif // _KERNEL_TSTL 137 | ptr = nullptr; 138 | } 139 | 140 | /* 141 | 初始化全局变量 init_global_vars 142 | 销毁全局变量 destory_global_vars 143 | */ 144 | template 145 | constexpr decltype(auto) init_global_vars(T& theArg) { 146 | using npType = typename Tstl::remove_pointer::type; 147 | theArg = Tstl::new_mem(); 148 | } 149 | 150 | template 151 | constexpr decltype(auto) init_global_vars(T& theArg, Args&&... nArgs) { 152 | init_global_vars(theArg); 153 | init_global_vars(Tstl::forward(nArgs)...); 154 | } 155 | 156 | template 157 | constexpr decltype(auto) destory_global_vars(T& theArg) { 158 | theArg->_destory(); 159 | del_mem(theArg); 160 | theArg = nullptr; 161 | } 162 | 163 | template 164 | constexpr decltype(auto) destory_global_vars(T& theArg, Args&&... nArgs) { 165 | destory_global_vars(theArg); 166 | destory_global_vars(Tstl::forward(nArgs)...); 167 | } 168 | 169 | template 170 | class Constructor { 171 | public: 172 | Constructor() { 173 | _Object = Tstl::new_mem(); 174 | } 175 | ~Constructor() { 176 | Tstl::del_mem(_Object); 177 | } 178 | 179 | public: 180 | template 181 | decltype(auto) init_args(Args&&... nArgs) { 182 | _Object->_init(Tstl::forward(nArgs)...); 183 | } 184 | 185 | decltype(auto) get() const { 186 | return *_Object; 187 | } 188 | 189 | private: 190 | T* _Object = nullptr; 191 | }; 192 | 193 | } // namespace Tstl 194 | 195 | #undef _EMPTY_ARGUMENT 196 | #undef _CLASS_DEFINE_CV 197 | 198 | #endif // !_TUTILS_H_HPP_ 199 | -------------------------------------------------------------------------------- /test/r0/r0.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define _KERNEL_TSTL 3 | #include 4 | #include "../test.hpp" 5 | 6 | EXTERN_C 7 | void DriverUnload(_DRIVER_OBJECT* DriverObject) { 8 | UNREFERENCED_PARAMETER(DriverObject); 9 | 10 | // 销毁 11 | Test::__destory(); 12 | } 13 | 14 | EXTERN_C 15 | NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath) { 16 | UNREFERENCED_PARAMETER(RegistryPath); 17 | DriverObject->DriverUnload = DriverUnload; 18 | 19 | // 初始化 20 | Test::__init(); 21 | 22 | Test::test_g_class(); 23 | Test::test_l_class(); 24 | 25 | return STATUS_SUCCESS; 26 | } -------------------------------------------------------------------------------- /test/r0/r0.inf: -------------------------------------------------------------------------------- 1 | ; 2 | ; r0.inf 3 | ; 4 | 5 | [Version] 6 | Signature="$WINDOWS NT$" 7 | Class=System 8 | ClassGuid={4d36e97d-e325-11ce-bfc1-08002be10318} 9 | Provider=%ManufacturerName% 10 | DriverVer= 11 | CatalogFile=r0.cat 12 | 13 | [DestinationDirs] 14 | DefaultDestDir = 12 15 | 16 | 17 | [SourceDisksNames] 18 | 1 = %DiskName%,,,"" 19 | 20 | [SourceDisksFiles] 21 | 22 | 23 | [Manufacturer] 24 | %ManufacturerName%=Standard,NT$ARCH$ 25 | 26 | [Standard.NT$ARCH$] 27 | 28 | 29 | [Strings] 30 | ManufacturerName="" ;TODO: Replace with your manufacturer name 31 | ClassName="" 32 | DiskName="r0 Source Disk" 33 | -------------------------------------------------------------------------------- /test/r0/r0.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | Debug 22 | ARM 23 | 24 | 25 | Release 26 | ARM 27 | 28 | 29 | Debug 30 | ARM64 31 | 32 | 33 | Release 34 | ARM64 35 | 36 | 37 | 38 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6} 39 | {dd38f7fc-d7bd-488b-9242-7d8754cde80d} 40 | v4.5 41 | 12.0 42 | Debug 43 | Win32 44 | r0 45 | $(LatestTargetPlatformVersion) 46 | 47 | 48 | 49 | Windows10 50 | true 51 | WindowsKernelModeDriver10.0 52 | Driver 53 | WDM 54 | 55 | 56 | Windows10 57 | false 58 | WindowsKernelModeDriver10.0 59 | Driver 60 | WDM 61 | 62 | 63 | Windows7 64 | true 65 | WindowsKernelModeDriver10.0 66 | Driver 67 | WDM 68 | 69 | 70 | Windows10 71 | false 72 | WindowsKernelModeDriver10.0 73 | Driver 74 | WDM 75 | 76 | 77 | Windows10 78 | true 79 | WindowsKernelModeDriver10.0 80 | Driver 81 | WDM 82 | 83 | 84 | Windows10 85 | false 86 | WindowsKernelModeDriver10.0 87 | Driver 88 | WDM 89 | 90 | 91 | Windows10 92 | true 93 | WindowsKernelModeDriver10.0 94 | Driver 95 | WDM 96 | 97 | 98 | Windows10 99 | false 100 | WindowsKernelModeDriver10.0 101 | Driver 102 | WDM 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | DbgengKernelDebugger 114 | 115 | 116 | DbgengKernelDebugger 117 | 118 | 119 | DbgengKernelDebugger 120 | $(SolutionDir)bin64\ 121 | 122 | 123 | DbgengKernelDebugger 124 | 125 | 126 | DbgengKernelDebugger 127 | 128 | 129 | DbgengKernelDebugger 130 | 131 | 132 | DbgengKernelDebugger 133 | 134 | 135 | DbgengKernelDebugger 136 | 137 | 138 | 139 | ..\..\src;%(AdditionalIncludeDirectories) 140 | stdcpp17 141 | Level3 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /test/r0/r0.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;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 | {8E41214B-6785-4CFE-B992-037D68949A14} 18 | inf;inv;inx;mof;mc; 19 | 20 | 21 | 22 | 23 | Driver Files 24 | 25 | 26 | 27 | 28 | Source Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | -------------------------------------------------------------------------------- /test/r3/r3.cpp: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include 3 | #include 4 | #include "../test.hpp" 5 | 6 | int main() { 7 | Test::__init(); 8 | Test::test_g_class(); 9 | Test::test_l_class(); 10 | Test::__destory(); 11 | return 1; 12 | } -------------------------------------------------------------------------------- /test/r3/r3.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {F815B2F9-A955-4FB6-AA97-DE8AF3D9AE28} 24 | r3 25 | 10.0.18362.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v141 32 | MultiByte 33 | 34 | 35 | Application 36 | false 37 | v141 38 | true 39 | MultiByte 40 | 41 | 42 | Application 43 | true 44 | v141 45 | MultiByte 46 | 47 | 48 | Application 49 | false 50 | v141 51 | true 52 | MultiByte 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | $(SolutionDir)bin64\ 74 | 75 | 76 | 77 | Level3 78 | Disabled 79 | true 80 | true 81 | 82 | 83 | Console 84 | 85 | 86 | 87 | 88 | Level3 89 | Disabled 90 | true 91 | true 92 | ..\..\src;%(AdditionalIncludeDirectories) 93 | stdcpp17 94 | 95 | 96 | Console 97 | 98 | 99 | 100 | 101 | Level3 102 | MaxSpeed 103 | true 104 | true 105 | true 106 | true 107 | 108 | 109 | Console 110 | true 111 | true 112 | 113 | 114 | 115 | 116 | Level3 117 | MaxSpeed 118 | true 119 | true 120 | true 121 | true 122 | 123 | 124 | Console 125 | true 126 | true 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /test/r3/r3.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;ipp;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 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/r3/r3.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /test/test.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _TEST_HPP_ 2 | #define _TEST_HPP_ 3 | 4 | #ifndef _KERNEL_TSTL 5 | #include "stdio.h" 6 | #else 7 | #define printf_s DbgPrint 8 | #endif 9 | 10 | namespace Test { 11 | 12 | class MyClass { 13 | public: 14 | MyClass() { 15 | printf_s("地址:%p 构造: %s\n", this, __FUNCSIG__); 16 | } 17 | MyClass(int i): m_value(i) { 18 | printf_s("地址:%p 构造: %s\n", this, __FUNCSIG__); 19 | } 20 | 21 | ~MyClass() { 22 | printf_s("地址:%p 析构:%s\n", this, __FUNCSIG__); 23 | } 24 | void _destory() { 25 | // 析构函数 26 | printf_s("地址:%p 析构:%s\n", this, __FUNCSIG__); 27 | } 28 | 29 | MyClass(const MyClass& t) { 30 | printf_s("地址:%p 拷贝构造: %s\n", this, __FUNCSIG__); 31 | 32 | if (&t == this) { 33 | return; 34 | } 35 | this->m_value = t.m_value; 36 | return; 37 | } 38 | 39 | MyClass(MyClass&& t) { 40 | printf_s("地址:%p 拷贝构造: %s\n", this, __FUNCSIG__); 41 | if (&t == this) { 42 | return; 43 | } 44 | this->m_value = t.m_value; 45 | t.m_value = 0; 46 | return; 47 | } 48 | 49 | MyClass& operator=(const MyClass& t) { 50 | printf_s("地址:%p 赋值构造: %s\n", this, __FUNCSIG__); 51 | if (&t == this) { 52 | return *this; 53 | } 54 | this->m_value = t.m_value; 55 | return *this; 56 | } 57 | 58 | MyClass& operator=(MyClass&& t) { 59 | printf_s("地址:%p 赋值构造: %s\n", this, __FUNCSIG__); 60 | if (&t == this) { 61 | return *this; 62 | } 63 | this->m_value = t.m_value; 64 | t.m_value = 0; 65 | return *this; 66 | } 67 | 68 | bool operator==(const MyClass& t) { 69 | if (&t == this) { 70 | return true; 71 | } 72 | return this->m_value == t.m_value ? false : true; 73 | } 74 | 75 | public: 76 | void test1() { 77 | printf_s("地址:%p 成员函数: %s\n", this, __FUNCSIG__); 78 | } 79 | 80 | virtual void test2() { 81 | // 不支持 82 | printf_s("地址:%p 虚函数: %s\n", this, __FUNCSIG__); 83 | } 84 | 85 | private: 86 | int m_value; 87 | }; 88 | 89 | Tstl::TList* gtest; 90 | Tstl::TList* g_listMyclass1; 91 | Tstl::TList* g_listMyclass2; 92 | MyClass* g_MyClass; 93 | 94 | void __init() { 95 | Tstl::init_global_vars(g_listMyclass1, gtest, g_listMyclass2, g_MyClass); 96 | } 97 | 98 | void __destory() { 99 | Tstl::destory_global_vars(g_listMyclass1, gtest, g_listMyclass2, g_MyClass); 100 | } 101 | 102 | // 测试全局变量 103 | void test_g_class() { 104 | // Tstl::Constructor t3 , t4; 105 | // t3.init_args(1); 106 | // t4.init_args(2); 107 | 108 | // t3.get().m_str = "t1"; 109 | // t4.get().m_str = "t2"; 110 | // gmyclass->add(t3); 111 | // gmyclass->add(t4); 112 | 113 | MyClass t1(1), t2(2), t3(6); 114 | MyClass ttt1 = t1; 115 | auto ttt2 = t1; 116 | ttt2 = t1; 117 | 118 | g_listMyclass1->add(t1); 119 | g_listMyclass1->add(t2); 120 | g_listMyclass1->add(Tstl::move(t3)); 121 | 122 | g_listMyclass1->remove(t1); 123 | g_listMyclass1->clear(); 124 | 125 | auto fun = [](MyClass& my, int a, int b) { 126 | g_MyClass->test1(); 127 | my.test1(); 128 | // my.test2(); 129 | return a + b; 130 | }; 131 | auto testff = fun(t1, 1, 2); 132 | } 133 | 134 | // 测试局部变量 135 | void test_l_class() { 136 | Tstl::TList listMyclass; 137 | MyClass t1(1), t2(2), t3(6); 138 | MyClass ttt1 = t1; 139 | auto ttt2 = t1; 140 | ttt2 = t1; 141 | 142 | listMyclass.add(t1); 143 | listMyclass.add(t2); 144 | listMyclass.add(Tstl::move(t3)); 145 | listMyclass.remove(t1); 146 | listMyclass.clear(); 147 | 148 | auto fun = [](MyClass& my, int a, int b) { 149 | g_MyClass->test1(); 150 | my.test1(); 151 | // my.test2(); 152 | return a + b; 153 | }; 154 | auto testff = fun(t1, 1, 2); 155 | } 156 | 157 | } // namespace Test 158 | 159 | #endif // !_TEST_HPP_ 160 | -------------------------------------------------------------------------------- /test/test.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.960 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "r3", "r3\r3.vcxproj", "{F815B2F9-A955-4FB6-AA97-DE8AF3D9AE28}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "r0", "r0\r0.vcxproj", "{117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|ARM = Debug|ARM 13 | Debug|ARM64 = Debug|ARM64 14 | Debug|x64 = Debug|x64 15 | Debug|x86 = Debug|x86 16 | Release|ARM = Release|ARM 17 | Release|ARM64 = Release|ARM64 18 | Release|x64 = Release|x64 19 | Release|x86 = Release|x86 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {F815B2F9-A955-4FB6-AA97-DE8AF3D9AE28}.Debug|ARM.ActiveCfg = Debug|Win32 23 | {F815B2F9-A955-4FB6-AA97-DE8AF3D9AE28}.Debug|ARM64.ActiveCfg = Debug|Win32 24 | {F815B2F9-A955-4FB6-AA97-DE8AF3D9AE28}.Debug|x64.ActiveCfg = Debug|x64 25 | {F815B2F9-A955-4FB6-AA97-DE8AF3D9AE28}.Debug|x64.Build.0 = Debug|x64 26 | {F815B2F9-A955-4FB6-AA97-DE8AF3D9AE28}.Debug|x86.ActiveCfg = Debug|Win32 27 | {F815B2F9-A955-4FB6-AA97-DE8AF3D9AE28}.Debug|x86.Build.0 = Debug|Win32 28 | {F815B2F9-A955-4FB6-AA97-DE8AF3D9AE28}.Release|ARM.ActiveCfg = Release|Win32 29 | {F815B2F9-A955-4FB6-AA97-DE8AF3D9AE28}.Release|ARM64.ActiveCfg = Release|Win32 30 | {F815B2F9-A955-4FB6-AA97-DE8AF3D9AE28}.Release|x64.ActiveCfg = Release|x64 31 | {F815B2F9-A955-4FB6-AA97-DE8AF3D9AE28}.Release|x64.Build.0 = Release|x64 32 | {F815B2F9-A955-4FB6-AA97-DE8AF3D9AE28}.Release|x86.ActiveCfg = Release|Win32 33 | {F815B2F9-A955-4FB6-AA97-DE8AF3D9AE28}.Release|x86.Build.0 = Release|Win32 34 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Debug|ARM.ActiveCfg = Debug|ARM 35 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Debug|ARM.Build.0 = Debug|ARM 36 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Debug|ARM.Deploy.0 = Debug|ARM 37 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Debug|ARM64.ActiveCfg = Debug|ARM64 38 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Debug|ARM64.Build.0 = Debug|ARM64 39 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Debug|ARM64.Deploy.0 = Debug|ARM64 40 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Debug|x64.ActiveCfg = Debug|x64 41 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Debug|x64.Build.0 = Debug|x64 42 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Debug|x64.Deploy.0 = Debug|x64 43 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Debug|x86.ActiveCfg = Debug|Win32 44 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Debug|x86.Build.0 = Debug|Win32 45 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Debug|x86.Deploy.0 = Debug|Win32 46 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Release|ARM.ActiveCfg = Release|ARM 47 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Release|ARM.Build.0 = Release|ARM 48 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Release|ARM.Deploy.0 = Release|ARM 49 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Release|ARM64.ActiveCfg = Release|ARM64 50 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Release|ARM64.Build.0 = Release|ARM64 51 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Release|ARM64.Deploy.0 = Release|ARM64 52 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Release|x64.ActiveCfg = Release|x64 53 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Release|x64.Build.0 = Release|x64 54 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Release|x64.Deploy.0 = Release|x64 55 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Release|x86.ActiveCfg = Release|Win32 56 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Release|x86.Build.0 = Release|Win32 57 | {117CCB1A-CE34-4BF0-BA97-F6A204D7F7C6}.Release|x86.Deploy.0 = Release|Win32 58 | EndGlobalSection 59 | GlobalSection(SolutionProperties) = preSolution 60 | HideSolutionNode = FALSE 61 | EndGlobalSection 62 | GlobalSection(ExtensibilityGlobals) = postSolution 63 | SolutionGuid = {ADF2445B-B327-4A60-A4C0-08DA63CF4B47} 64 | EndGlobalSection 65 | EndGlobal 66 | --------------------------------------------------------------------------------