diff options
author | Norbert Preining <norbert@preining.info> | 2021-12-28 03:01:00 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2021-12-28 03:01:00 +0000 |
commit | ecdf859b6ce481abfd530425dcf6f0f764bd0001 (patch) | |
tree | 13bc161dc046876ac6c92fce5f9f5034ba9aa573 /graphics/asymptote/makeUnique.h | |
parent | 790995b7e79697514364450bf9c04f1b8d500838 (diff) |
CTAN sync 202112280300
Diffstat (limited to 'graphics/asymptote/makeUnique.h')
-rw-r--r-- | graphics/asymptote/makeUnique.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/graphics/asymptote/makeUnique.h b/graphics/asymptote/makeUnique.h new file mode 100644 index 0000000000..6bf84bbf43 --- /dev/null +++ b/graphics/asymptote/makeUnique.h @@ -0,0 +1,43 @@ +#pragma once + +#include <cstddef> +#include <memory> +#include <type_traits> +#include <utility> + +#if __cplusplus < 201402L + +namespace utils { +template<class T> struct _Unique_if { + typedef std::unique_ptr<T> _Single_object; +}; + +template<class T> struct _Unique_if<T[]> { + typedef std::unique_ptr<T[]> _Unknown_bound; +}; + +template<class T, size_t N> struct _Unique_if<T[N]> { + typedef void _Known_bound; +}; + +template<class T, class... Args> +typename _Unique_if<T>::_Single_object +make_unique(Args&&... args) { + return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); +} + +template<class T> +typename _Unique_if<T>::_Unknown_bound +make_unique(size_t n) { + typedef typename std::remove_extent<T>::type U; + return std::unique_ptr<T>(new U[n]()); +} + +template<class T, class... Args> +typename _Unique_if<T>::_Known_bound +make_unique(Args&&...) = delete; +} +using utils::make_unique; +#else +using std::make_unique; +#endif |