From acf53881d880f1a76b1eb799263dc1b2550ad485 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 10 Aug 2016 15:38:36 +0200 Subject: compat/make-unique: add std::make_unique sample impl It's not present in GNU with -std=c++14 --- opentrack-compat/make-unique.hpp | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 opentrack-compat/make-unique.hpp diff --git a/opentrack-compat/make-unique.hpp b/opentrack-compat/make-unique.hpp new file mode 100644 index 00000000..bb5315c5 --- /dev/null +++ b/opentrack-compat/make-unique.hpp @@ -0,0 +1,43 @@ +#pragma once + +// GNU 5.4.0 doesn't have std::make_unique in -std=c++14 mode + +// this implementation was taken from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3656.htm + +#include +#include +#include + +namespace detail { +template struct Unique_if +{ + typedef std::unique_ptr Single_object; +}; + +template struct Unique_if +{ + typedef std::unique_ptr Unknown_bound; +}; + +template struct Unique_if +{ + typedef void Known_bound; +}; +} + +template + typename detail::Unique_if::Single_object + make_unique(Args&&... args) { + return std::unique_ptr(new T(std::forward(args)...)); + } + +template + typename detail::Unique_if::Unknown_bound + make_unique(std::size_t n) { + typedef typename std::remove_extent::type U; + return std::unique_ptr(new U[n]()); + } + +template + typename detail::Unique_if::Known_bound + make_unique(Args&&...) = delete; -- cgit v1.2.3