diff --git a/include/common.h b/include/common.h index a9b5daf..fddfd9f 100644 --- a/include/common.h +++ b/include/common.h @@ -31,6 +31,32 @@ constexpr bool x64 = false; template using Array = T[]; +template using Functor = std::integral_constant, F>; + +template +struct Identity { V operator()(V v) const { return v; } }; + +struct PermissivePointer +{ + template + operator T*() { return (T*)p; } + void* p; +}; + +template > +class AutoHandle +{ +public: + AutoHandle(HANDLE h) : h(h) {} + operator HANDLE() { return h.get(); } + PHANDLE operator&() { static_assert(sizeof(*this) == sizeof(HANDLE)); assert(!h); return (PHANDLE)this; } + operator bool() { return h.get() != NULL && h.get() != INVALID_HANDLE_VALUE; } + +private: + struct HandleCleaner { void operator()(void* h) { if (h != INVALID_HANDLE_VALUE) HandleCloser()(PermissivePointer{ h }); } }; + std::unique_ptr h; +}; + template class Synchronized { @@ -53,23 +79,6 @@ private: M m; }; -template -using Functor = std::integral_constant, F>; - -template > -class AutoHandle -{ -public: - AutoHandle(HANDLE h) : h(h) {} - operator HANDLE() { return h.get(); } - PHANDLE operator&() { static_assert(sizeof(*this) == sizeof(HANDLE)); return (PHANDLE)this; } - operator bool() { return h.get() != NULL && h.get() != INVALID_HANDLE_VALUE; } - -private: - struct HandleCleaner { void operator()(void* h) { if (h != INVALID_HANDLE_VALUE) HandleCloser()(h); } }; - std::unique_ptr h; -}; - static struct { BYTE DUMMY[100]; diff --git a/test/main.cpp b/test/main.cpp index 14b5810..3535971 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -13,7 +13,7 @@ int& mode = vars.at(0); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int _) { QApplication a(_ = 0, DUMMY); - static std::vector, Functor>> extensions; + static std::vector>> extensions; for (auto file : std::filesystem::directory_iterator(std::filesystem::current_path())) if (file.path().extension() == L".dll" && (std::stringstream() << std::ifstream(file.path(), std::ios::binary).rdbuf()).str().find("OnNewSentence") != std::string::npos)