// // Created by EmsiaetKadosh on 25-1-14. // #pragma once #include #include #include #include #include #include #include using wchar = wchar_t; using QWORD = unsigned long long int; using String = std::wstring; using Thread = std::thread; template, typename Alloc = std::allocator>> using Map = std::map; template> using List = std::list; template using Function = std::function; #define Success() { return 0; } #define Failed() { return 1; } #define Error() { return -1; } #if false #ifdef _MSC_VER #define __FUNCSIGW__ L"" __FUNCSIG__ #elif defined(__GNUC__) || defined(__clang__) #define __FUNCSIGW__ L"" __PRETTY_FUNCTION__ #else #define __FUNCSIGW__ L"" __func__ #endif #endif #define _WINSOCKAPI_ /* 防止winsock.h被引入。winsock.h和winsock2.h冲突。 */ #if false #include #endif #define NOMINMAX #include #include #include #include #include #include #include #include #include #pragma comment(lib, "Msimg32.lib") #pragma comment(lib, "ws2_32.lib") #pragma comment(lib, "dwmapi.lib") #pragma comment(lib, "Uxtheme.lib") #pragma comment(lib, "winmm.lib") template concept Copyable = requires(const T& t) { T(t); }; template concept NewCopyable = requires(const T& t) { delete new T(t); }; template concept Moveable = requires(T&& t) { T(std::move(t)); }; template concept NewMoveable = requires(T&& t) { delete new T(std::move(t)); }; template concept NonreferenceType = !std::is_reference_v; template concept NonpointerType = !std::is_pointer_v; template concept ReferenceType = std::is_reference_v; template concept PointerType = std::is_pointer_v; template concept TypeName = NonreferenceType && NonpointerType; template class ObjectHolder { Base* value; bool hasValue; char padding[7]{}; public: /** * 用于延迟初始化。 */ ObjectHolder() : value(nullptr), hasValue(false) {} ObjectHolder(Base* const value) : value(value), hasValue(false) {} template requires std::is_base_of_v && TypeName ObjectHolder(const T& value) : value(new T(value)), hasValue(true) {} template requires std::is_base_of_v && TypeName ObjectHolder(T&& value) : value(new T(std::forward(value))), hasValue(true) {} ObjectHolder(const ObjectHolder& other) noexcept: value(other.value), hasValue(false) {} ObjectHolder(ObjectHolder&& other) noexcept: value(other.value), hasValue(other.hasValue) { other.value = nullptr; other.hasValue = false; } template requires std::is_base_of_v && TypeName void set(const T& value); template requires std::is_base_of_v && TypeName void set(T&& value); ~ObjectHolder() { if (hasValue) delete value; value = nullptr; } Base& operator->() noexcept(false); const Base& operator->() const noexcept(false); Base& operator*() noexcept(false); const Base& operator*() const noexcept(false); operator bool() const noexcept { return value; } }; enum class ReferenceValueType { LVALUE, RVALUE }; template class Reference { const T* lvalue = nullptr; T* rvalue = nullptr; public: const ReferenceValueType type; Reference(const T& lvalue) : lvalue(&lvalue), type(ReferenceValueType::LVALUE) {} Reference(T&& rvalue) : rvalue(&rvalue), type(ReferenceValueType::RVALUE) {} Reference& operator=(const Reference&) = delete; Reference& operator=(Reference&&) = delete; Reference& operator=(const T& lvalue) { this->lvalue = &lvalue; this->type = ReferenceValueType::LVALUE; return *this; } Reference& operator=(T&& rvalue) { this->rvalue = &rvalue; this->type = ReferenceValueType::RVALUE; return *this; } const T& getLvalue() const noexcept(false); T&& getRvalue() noexcept(false); };