From a98326eb2954ac1e79f5eac28dbeab3ec15e047f Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Sat, 30 Jun 2018 12:43:08 +0200 Subject: 10.1 --- zen/stl_tools.h | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) (limited to 'zen/stl_tools.h') diff --git a/zen/stl_tools.h b/zen/stl_tools.h index f09639e1..2ce2cf33 100755 --- a/zen/stl_tools.h +++ b/zen/stl_tools.h @@ -12,7 +12,7 @@ #include #include #include -#include "type_tools.h" +#include "type_traits.h" #include "build_info.h" @@ -54,10 +54,6 @@ template BidirectionalIterator1 search_last(BidirectionalIterator1 first1, BidirectionalIterator1 last1, BidirectionalIterator2 first2, BidirectionalIterator2 last2); -template -bool equal(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2); - template Num hashBytes (ByteIterator first, ByteIterator last); template Num hashBytesAppend(Num hashVal, ByteIterator first, ByteIterator last); @@ -69,7 +65,7 @@ struct StringHash { const auto* strFirst = strBegin(str); return hashBytes(reinterpret_cast(strFirst), - reinterpret_cast(strFirst + strLength(str))); + reinterpret_cast(strFirst + strLength(str))); } }; @@ -181,35 +177,25 @@ BidirectionalIterator1 search_last(const BidirectionalIterator1 first1, Bi } -template inline -bool equal(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2) -{ - return last1 - first1 == last2 - first2 && std::equal(first1, last1, first2); -} - - - - //FNV-1a: http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function template inline -Num hashBytes(ByteIterator first, ByteIterator last) +Num hashBytes(ByteIterator first, ByteIterator last) { - static_assert(std::is_integral::value, ""); - static_assert(sizeof(Num) == 4 || sizeof(Num) == 8, ""); //macOS: size_t is "unsigned long" - const Num base = sizeof(Num) == 4 ? 2166136261U : 14695981039346656037ULL; + static_assert(IsInteger::value); + static_assert(sizeof(Num) == 4 || sizeof(Num) == 8); //macOS: size_t is "unsigned long" + constexpr Num base = sizeof(Num) == 4 ? 2166136261U : 14695981039346656037ULL; - return hashBytesAppend(base, first, last); + return hashBytesAppend(base, first, last); } template inline Num hashBytesAppend(Num hashVal, ByteIterator first, ByteIterator last) { - static_assert(sizeof(typename std::iterator_traits::value_type) == 1, ""); - const Num prime = sizeof(Num) == 4 ? 16777619U : 1099511628211ULL; + static_assert(sizeof(typename std::iterator_traits::value_type) == 1); + constexpr Num prime = sizeof(Num) == 4 ? 16777619U : 1099511628211ULL; - for (; first != last; ++first) + for (; first != last; ++first) { hashVal ^= static_cast(*first); hashVal *= prime; -- cgit