From 60e87889d6438e386acf58c3967fb874af9aae82 Mon Sep 17 00:00:00 2001 From: mitchell Date: Sun, 5 Jan 2020 21:22:02 -0500 Subject: Added Sci::make_unique() and Sci::size() for better compatibility with the default branch. std::make_unique() is c++14 and std::size() is c++17. --- include/Compat.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 include/Compat.h (limited to 'include/Compat.h') diff --git a/include/Compat.h b/include/Compat.h new file mode 100644 index 000000000..712ff1373 --- /dev/null +++ b/include/Compat.h @@ -0,0 +1,51 @@ +// c++11 compatibility with some c++14 features and higher. +// This helps minimize changes from the default branch. + +#ifndef COMPAT_H +#define COMPAT_H + +#ifdef __cplusplus + +#include +#include +#include +#include + +namespace Sci { + +// std::make_unique +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 _Unique_if::_Single_object + make_unique(Args&&... args) { + return std::unique_ptr(new T(std::forward(args)...)); + } +template + typename _Unique_if::_Unknown_bound + make_unique(size_t n) { + typedef typename std::remove_extent::type U; + return std::unique_ptr(new U[n]()); + } +template + typename _Unique_if::_Known_bound + make_unique(Args&&...) = delete; + +// std::size +template +constexpr size_t size(const T (&)[N]) noexcept { + return N; +} + +} + +#endif + +#endif \ No newline at end of file -- cgit v1.2.3