diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2013-02-18 19:20:35 -0800 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2013-02-20 18:27:30 -0800 |
commit | 25823b36905a84d92f9299ba7f9f0c713141c8fb (patch) | |
tree | a335120de1c4618c9b41391e70bc621a4218010c /src/common/utils2.hpp | |
parent | a5d231b6a60a4ab868918850be24640e88843825 (diff) | |
download | tmwa-25823b36905a84d92f9299ba7f9f0c713141c8fb.tar.gz tmwa-25823b36905a84d92f9299ba7f9f0c713141c8fb.tar.bz2 tmwa-25823b36905a84d92f9299ba7f9f0c713141c8fb.tar.xz tmwa-25823b36905a84d92f9299ba7f9f0c713141c8fb.zip |
Strictify map cells
Also fix a small but major bug in map_randfreecell.
Diffstat (limited to 'src/common/utils2.hpp')
-rw-r--r-- | src/common/utils2.hpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/common/utils2.hpp b/src/common/utils2.hpp index cdf2069..5f02beb 100644 --- a/src/common/utils2.hpp +++ b/src/common/utils2.hpp @@ -5,6 +5,7 @@ #include <functional> #include <iterator> +#include <memory> #include <type_traits> #ifdef __clang__ @@ -208,4 +209,22 @@ typename std::common_type<A, B>::type max(A a, B b) return b < a ? a : b; } +template<class T> +struct is_array_of_unknown_bound +: std::is_same<T, typename std::remove_extent<T>::type[]> +{}; + +template<class T, class... A> +typename std::enable_if<!is_array_of_unknown_bound<T>::value, std::unique_ptr<T>>::type make_unique(A&&... a) +{ + return std::unique_ptr<T>(new T(a...)); +} + +template<class T> +typename std::enable_if<is_array_of_unknown_bound<T>::value, std::unique_ptr<T>>::type make_unique(size_t sz) +{ + typedef typename std::remove_extent<T>::type E; + return std::unique_ptr<E[]>(new E[sz]); +} + #endif // UTILS2_HPP |