From 8f35d6d3a961957fe4e6ac428a1c19270e519cb5 Mon Sep 17 00:00:00 2001 From: Daniel Brunner <0xFEEDC0DE64@gmail.com> Date: Thu, 4 Oct 2018 23:59:22 +0200 Subject: [PATCH] Added cpp14polyfills.h --- DbCoreLib.pro | 1 + cpp14polyfills.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 cpp14polyfills.h diff --git a/DbCoreLib.pro b/DbCoreLib.pro index e0817db..8c9e52f 100644 --- a/DbCoreLib.pro +++ b/DbCoreLib.pro @@ -13,6 +13,7 @@ SOURCES += \ utils/jsonutils.cpp HEADERS += dbcorelib_global.h \ + cpp14polyfills.h \ fixedsizematrix.h \ randomdevice.h \ utils/timeutils.h \ diff --git a/cpp14polyfills.h b/cpp14polyfills.h new file mode 100644 index 0000000..d345a00 --- /dev/null +++ b/cpp14polyfills.h @@ -0,0 +1,43 @@ +#pragma once + +#if __cplusplus < 201402L && _MSC_VER < 1800 + +// std includes +#include +#include +#include +#include +#include + +namespace std { + template struct _Unique_if { + typedef unique_ptr _Single_object; + }; + + template struct _Unique_if { + typedef unique_ptr _Unknown_bound; + }; + + template struct _Unique_if { + typedef void _Known_bound; + }; + + template + typename _Unique_if::_Single_object + make_unique(Args&&... args) { + return unique_ptr(new T(std::forward(args)...)); + } + + template + typename _Unique_if::_Unknown_bound + make_unique(size_t n) { + typedef typename remove_extent::type U; + return unique_ptr(new U[n]()); + } + + template + typename _Unique_if::_Known_bound + make_unique(Args&&...) = delete; +} + +#endif // __cplusplus < 201402L