diff options
author | Daniel Wilhelm <daniel@wili.li> | 2015-10-02 14:53:20 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2015-10-02 14:53:20 +0200 |
commit | 94db751716dd2851f99b5c4c2981da1d1f4780f8 (patch) | |
tree | e4ffc9f5ae2b2873f267a6e5d3d2092c8aad49a7 /zen/stl_tools.h | |
parent | 6.10 (diff) | |
download | FreeFileSync-94db751716dd2851f99b5c4c2981da1d1f4780f8.tar.gz FreeFileSync-94db751716dd2851f99b5c4c2981da1d1f4780f8.tar.bz2 FreeFileSync-94db751716dd2851f99b5c4c2981da1d1f4780f8.zip |
6.11
Diffstat (limited to 'zen/stl_tools.h')
-rw-r--r-- | zen/stl_tools.h | 70 |
1 files changed, 12 insertions, 58 deletions
diff --git a/zen/stl_tools.h b/zen/stl_tools.h index 38752e67..eb94b4a1 100644 --- a/zen/stl_tools.h +++ b/zen/stl_tools.h @@ -9,13 +9,6 @@ #include <memory> #include <algorithm> -#if defined _MSC_VER && _MSC_VER <= 1600 -#include <set> -#include <map> -#else -#include <unordered_set> -#include <unordered_map> -#endif //enhancements for <algorithm> @@ -38,8 +31,8 @@ template <class M, class K, class V> V& map_add_or_update(M& map, const K& key, const V& value); //efficient add or update without "default-constructible" requirement (Effective STL, item 24) //binary search returning an iterator -template <class ForwardIterator, class T, typename Compare> -ForwardIterator binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); +template <class ForwardIterator, class T, typename CompLess> +ForwardIterator binary_search(ForwardIterator first, ForwardIterator last, const T& value, CompLess less); template <class BidirectionalIterator, class T> BidirectionalIterator find_last(BidirectionalIterator first, BidirectionalIterator last, const T& value); @@ -53,26 +46,9 @@ template <class InputIterator1, class InputIterator2> bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); -//hash container: proper name + mitigate MSVC performance bug -template <class T> class hash_set; -template <class K, class V> class hash_map; - -template<typename T, typename Arg1> -std::unique_ptr<T> make_unique(Arg1&& arg1); //should eventually make it into the std at some time - - - - - - - - - - - - - - +//until std::make_unique is available in GCC: +template <class T, class... Args> inline +std::unique_ptr<T> make_unique(Args&& ... args) { return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); } @@ -127,11 +103,11 @@ V& map_add_or_update(M& map, const K& key, const V& value) //efficient add or up } -template <class ForwardIterator, class T, typename Compare> inline -ForwardIterator binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp) +template <class ForwardIterator, class T, typename CompLess> inline +ForwardIterator binary_search(ForwardIterator first, ForwardIterator last, const T& value, CompLess less) { - first = std::lower_bound(first, last, value, comp); - if (first != last && !comp(value, *first)) + first = std::lower_bound(first, last, value, less); + if (first != last && !less(value, *first)) return first; else return last; @@ -187,32 +163,10 @@ bool equal(InputIterator1 first1, InputIterator1 last1, } -#if defined _MSC_VER && _MSC_VER <= 1600 //VS2010 performance bug in std::unordered_set<>: http://drdobbs.com/blogs/cpp/232200410 -> should be fixed in VS11 -template <class T> class hash_set : public std::set<T> {}; -template <class K, class V> class hash_map : public std::map<K, V> {}; -#else -template <class T> class hash_set : public std::unordered_set<T> {}; -template <class K, class V> class hash_map : public std::unordered_map<K, V> {}; -//C++11: -//template <class T> using hash_set = std::unordered_set<T>; -//template <class K, class V> using hash_map = std::unordered_map<K, V>; +#if defined _MSC_VER && _MSC_VER <= 1600 +//VS2010 performance bug in std::unordered_set<>: http://drdobbs.com/blogs/cpp/232200410 -> should be fixed in VS11 +static_assert(false, ""); #endif - -//as long as variadic templates are not available in MSVC -template<class T> inline std::unique_ptr<T> make_unique() { return std::unique_ptr<T>(new T); } -template<class T, class Arg1> inline std::unique_ptr<T> make_unique(Arg1&& arg1) { return std::unique_ptr<T>(new T(std::forward<Arg1>(arg1))); } -template<class T, class Arg1, class Arg2> inline std::unique_ptr<T> make_unique(Arg1&& arg1, Arg2&& arg2) { return std::unique_ptr<T>(new T(std::forward<Arg1>(arg1), std::forward<Arg2>(arg2))); } -template<class T, class Arg1, class Arg2, class Arg3> inline std::unique_ptr<T> make_unique(Arg1&& arg1, Arg2&& arg2, Arg3&& arg3) { return std::unique_ptr<T>(new T(std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3))); } -template<class T, class Arg1, class Arg2, class Arg3, class Arg4> inline std::unique_ptr<T> make_unique(Arg1&& arg1, Arg2&& arg2, Arg3&& arg3, Arg4&& arg4) { return std::unique_ptr<T>(new T(std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3), std::forward<Arg4>(arg4))); } -template<class T, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5> inline std::unique_ptr<T> make_unique(Arg1&& arg1, Arg2&& arg2, Arg3&& arg3, Arg4&& arg4, Arg5&& arg5) { return std::unique_ptr<T>(new T(std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3), std::forward<Arg4>(arg4), std::forward<Arg5>(arg5))); } -template<class T, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6> inline std::unique_ptr<T> make_unique(Arg1&& arg1, Arg2&& arg2, Arg3&& arg3, Arg4&& arg4, Arg5&& arg5, Arg6&& arg6) { return std::unique_ptr<T>(new T(std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3), std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6))); } -template<class T, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7> inline std::unique_ptr<T> make_unique(Arg1&& arg1, Arg2&& arg2, Arg3&& arg3, Arg4&& arg4, Arg5&& arg5, Arg6&& arg6, Arg7&& arg7) { return std::unique_ptr<T>(new T(std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3), std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6), std::forward<Arg7>(arg7))); } - -//template<typename T, typename ...Args> inline -//std::unique_ptr<T> make_unique(Args&& ...args) -//{ -// return std::unique_ptr<T>(new T( std::forward<Args>(args)... )); -//} } #endif //STL_TOOLS_HEADER_84567184321434 |