From daf72d3059dbdb5aab0b9fa596269f7e0b8ecacb Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Wed, 2 Oct 2019 19:47:51 +0200 Subject: [PATCH] Ensure AutoInit can only be used with std::shared_ptr (#266) --- lib/inc/drogon/IOThreadStorage.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/inc/drogon/IOThreadStorage.h b/lib/inc/drogon/IOThreadStorage.h index ddc0d2d8..78db6f0b 100644 --- a/lib/inc/drogon/IOThreadStorage.h +++ b/lib/inc/drogon/IOThreadStorage.h @@ -57,31 +57,33 @@ namespace drogon * @endcode */ template class StoragePtrType = std::shared_ptr> class IOThreadStorage { + private: + using IsSharedPtr = std::is_same, std::shared_ptr>; + + static_assert(!AutoInit || (AutoInit && IsSharedPtr::value), + "Default initialization only works with std::shared_ptr"); + public: - static const bool isConstructorInitialized = ConstructorInitialize; + static const bool isConstructorInitialized = AutoInit; using StoragePtr = StoragePtrType; using CreatorCallback = std::function; template ::value && - std::is_same, std::shared_ptr>::value && - ConstructorInitialize>::type> + IsSharedPtr::value && AutoInit>::type> IOThreadStorage() : IOThreadStorage([](size_t) { return std::make_shared(); }) { } - template < - typename U = C, - typename = typename std::enable_if< - !ConstructorInitialize || - !std::is_same, std::shared_ptr>::value>::type, - typename = U> + template ::type, + typename = U> IOThreadStorage() : IOThreadStorage([](size_t) { return nullptr; }) { }