diff --git a/examples/matt.cc b/examples/matt.cc index d18fd7f..205e167 100644 --- a/examples/matt.cc +++ b/examples/matt.cc @@ -86,7 +86,7 @@ void test(const char *name, Perturb perturb1, Perturb perturb2) Timer t(name); // start timer Set c; - c.reserve(order.size()); // whether this "reserve()" is present or not makes a huge difference + //c.reserve(order.size()); // whether this "reserve()" is present or not makes a huge difference c.insert(order.begin(), order.end()); // time for inserting the same keys into the set // should not depend on them being sorted or not. } diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index a339c95..f1b7996 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -1209,9 +1209,8 @@ public: // TODO(romanp): Once we stop supporting gcc 5.1 and below, replace // RequiresInsertable with RequiresInsertable. // We are hitting this bug: https://godbolt.org/g/1Vht4f. - template < - class T, RequiresInsertable = 0, - typename std::enable_if::value, int>::type = 0> + template = 0, + typename std::enable_if::value, int>::type = 0> std::pair insert(const T& value) { return emplace(value); } @@ -1235,9 +1234,8 @@ public: // TODO(romanp): Once we stop supporting gcc 5.1 and below, replace // RequiresInsertable with RequiresInsertable. // We are hitting this bug: https://godbolt.org/g/1Vht4f. - template < - class T, RequiresInsertable = 0, - typename std::enable_if::value, int>::type = 0> + template = 0, + typename std::enable_if::value, int>::type = 0> iterator insert(const_iterator, const T& value) { return insert(value).first; } @@ -1246,9 +1244,36 @@ public: return insert(std::move(value)).first; } - template + template + using IsRandomAccess = std::is_same::iterator_category, + std::random_access_iterator_tag>; + + + template + struct has_difference_operator + { + private: + using yes = std::true_type; + using no = std::false_type; + + template static auto test(int) -> decltype(std::declval() - std::declval() == 1, yes()); + template static no test(...); + + public: + static constexpr bool value = std::is_same(0)), yes>::value; + }; + + template ::value, int> = 0> void insert(InputIt first, InputIt last) { - for (; first != last; ++first) insert(*first); + this->reserve(this->size() + (last - first)); + for (; first != last; ++first) + insert(*first); + } + + template ::value, int> = 0> + void insert(InputIt first, InputIt last) { + for (; first != last; ++first) + insert(*first); } template = 0, RequiresInsertable = 0>