From 3aa080d536414807b368ba382e024616a442c079 Mon Sep 17 00:00:00 2001 From: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> Date: Thu, 20 Feb 2025 21:07:04 -0600 Subject: [PATCH] Remove a SFINAE check that keeps surfacing msvc bugs, fixes #215 --- src/utils/utils.hpp | 71 ++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp index 55c8c7b..3d50bec 100644 --- a/src/utils/utils.hpp +++ b/src/utils/utils.hpp @@ -201,25 +201,19 @@ namespace detail { // Also allow file_wrapper file = std::fopen(object_path.c_str(), "rb"); template< typename T, - typename D - // workaround for: + typename D, + // Note: Previously checked if D was invocable and returned void but this kept causing problems for MSVC // == 19.38-specific msvc bug https://developercommunity.visualstudio.com/t/MSVC-1938331290-preview-fails-to-comp/10505565 // <= 19.23 msvc also appears to fail (but for a different reason https://godbolt.org/z/6Y5EvdWPK) - #if !defined(_MSC_VER) || !(_MSC_VER <= 1923 || _MSC_VER == 1938) - , - typename std::enable_if< - std::is_same()(std::declval())), void>::value, - int - >::type = 0, - typename std::enable_if< - std::is_standard_layout::value && std::is_trivial::value, - int - >::type = 0, - typename std::enable_if< - std::is_nothrow_move_constructible::value, - int - >::type = 0 - #endif + // <= 19.39 msvc also has trouble with it for different reasons https://godbolt.org/z/aPPPT7z3z + typename std::enable_if< + std::is_standard_layout::value && std::is_trivial::value, + int + >::type = 0, + typename std::enable_if< + std::is_nothrow_move_constructible::value, + int + >::type = 0 > class raii_wrapper { T obj; @@ -251,22 +245,7 @@ namespace detail { } }; - template< - typename T, - typename D - // workaround a msvc bug https://developercommunity.visualstudio.com/t/MSVC-1938331290-preview-fails-to-comp/10505565 - #if !defined(_MSC_VER) || _MSC_VER != 1938 - , - typename std::enable_if< - std::is_same()(std::declval())), void>::value, - int - >::type = 0, - typename std::enable_if< - std::is_standard_layout::value && std::is_trivial::value, - int - >::type = 0 - #endif - > + template raii_wrapper::type, D> raii_wrap(T obj, D deleter) { return raii_wrapper::type, D>(obj, deleter); } @@ -298,6 +277,32 @@ namespace detail { return *ptr; } }; + + // template + // class scope_guard { + // F f; + // bool active; + // public: + // scope_guard(F&& f) : f(std::forward(f)), active(true) {} + // ~scope_guard() { + // if(active) { + // f(); + // } + // } + // scope_guard(const scope_guard&) = delete; + // scope_guard(scope_guard&& other) : f(std::move(other.f)), active(exchange(other.active, false)) {} + // scope_guard& operator=(const scope_guard&) = delete; + // scope_guard& operator=(scope_guard&& other) { + // f = std::move(other.f); + // active = exchange(other.active, false); + // return *this; + // } + // }; + + // template + // auto scope_exit(F&& f) { + // return scope_guard(std::forward(f)); + // } } }