diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-12-03 11:27:24 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-12-03 11:27:24 +0100 |
commit | 82f3574d09064a442e30eb2dc7639f473749c5bd (patch) | |
tree | dfb0aa6182a0d7d04b6131199d67ff90a87cb9c1 /include/mbgl/util | |
parent | 50669307c5648e62941a63e0c75dba8602448d9d (diff) | |
download | qtlocation-mapboxgl-82f3574d09064a442e30eb2dc7639f473749c5bd.tar.gz |
add array overloads to make_unique and move it to mbgl::util from std
Diffstat (limited to 'include/mbgl/util')
-rw-r--r-- | include/mbgl/util/std.hpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/include/mbgl/util/std.hpp b/include/mbgl/util/std.hpp index 051f89bb60..e64820de47 100644 --- a/include/mbgl/util/std.hpp +++ b/include/mbgl/util/std.hpp @@ -2,19 +2,34 @@ #define MBGL_UTIL_STD #include <memory> +#include <type_traits> +#include <utility> -namespace std { +namespace mbgl { +namespace util { + +// C++14 backfill based on http://llvm.org/svn/llvm-project/libcxx/trunk/include/memory + +namespace detail { +template<class T> struct unique_type { typedef ::std::unique_ptr<T> single; }; +template<class T> struct unique_type<T[]> { typedef ::std::unique_ptr<T[]> unknown_bound; }; +template<class T, size_t size> struct unique_type<T[size]> { typedef void known_bound; }; +} -// C++14 backfill from http://herbsutter.com/gotw/_102/ -template<typename T, typename ...Args> -::std::unique_ptr<T> make_unique(Args&& ...args) { +template<class T, class... Args> +typename detail::unique_type<T>::single make_unique(Args&&... args) { return ::std::unique_ptr<T>(new T(::std::forward<Args>(args)...)); } +template<class T> +typename detail::unique_type<T>::unknown_bound make_unique(size_t size) { + return ::std::unique_ptr<T>(new typename ::std::remove_extent<T>::type[size]()); } -namespace mbgl { -namespace util { +template<class T, class... Args> +typename detail::unique_type<T>::known_bound make_unique(Args&&...) = delete; + + template <typename Container, typename ForwardIterator, typename Predicate> void erase_if(Container &container, ForwardIterator it, const ForwardIterator end, Predicate pred) { |