From 38e0cd69637a91b0db5c6f340fd66eeaf94bb70c Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Wed, 16 Sep 2015 21:41:35 -0700 Subject: [PATCH] Provide compatibility shim for std::make_unique(). make_unique is C++14 only. This provides a shim for C++11-only compilers. Change-Id: Ibaa79822a7a6cfa8020c201c2edea1754650f570 --- wpilibc/wpilibC++/include/Base.h | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/wpilibc/wpilibC++/include/Base.h b/wpilibc/wpilibC++/include/Base.h index 396eeacc61..288d4afaf6 100644 --- a/wpilibc/wpilibC++/include/Base.h +++ b/wpilibc/wpilibC++/include/Base.h @@ -68,3 +68,41 @@ struct HasBeenMoved { std::atomic moved{false}; operator bool() const { return moved; } }; + +// Define make_unique for C++11-only compilers +#if __cplusplus == 201103L +#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; +} // namespace std +#endif