summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-06-19 11:54:11 +0200
committerGitHub <noreply@github.com>2019-06-19 11:54:11 +0200
commit558d6c15a6142895be7a51777e81c4061adec074 (patch)
tree67a3bdeb96c53927af5bc09906cf4c17ae35e820 /vespalib
parent6b03dcdb00d381a580e10dcb48a2f02a29d2810e (diff)
parent5ec7f81e6657eb2a45ef428f5b63c20cbf5986b4 (diff)
Merge pull request #9831 from vespa-engine/vekterli/replace-gcc-stl-internal-functions
Replace GCC-only `std::_Identity` and `std::_Select1st` with own code
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/stllike/hashtable_test.cpp3
-rw-r--r--vespalib/src/vespa/vespalib/stllike/hash_map.h3
-rw-r--r--vespalib/src/vespa/vespalib/stllike/hash_map.hpp11
-rw-r--r--vespalib/src/vespa/vespalib/stllike/hash_set.h3
-rw-r--r--vespalib/src/vespa/vespalib/stllike/hash_set.hpp5
-rw-r--r--vespalib/src/vespa/vespalib/stllike/identity.h18
-rw-r--r--vespalib/src/vespa/vespalib/stllike/select.h17
7 files changed, 50 insertions, 10 deletions
diff --git a/vespalib/src/tests/stllike/hashtable_test.cpp b/vespalib/src/tests/stllike/hashtable_test.cpp
index 4948faf450f..877a5dddcb5 100644
--- a/vespalib/src/tests/stllike/hashtable_test.cpp
+++ b/vespalib/src/tests/stllike/hashtable_test.cpp
@@ -3,6 +3,7 @@
#include <vespa/vespalib/stllike/hashtable.hpp>
#include <vespa/vespalib/stllike/hash_fun.h>
+#include <vespa/vespalib/stllike/identity.h>
#include <vespa/vespalib/testkit/testapp.h>
#include <memory>
#include <vector>
@@ -63,7 +64,7 @@ TEST("require that hashtable can store pairs of <key, unique_ptr to value>") {
}
template<typename K> using set_hashtable =
- hashtable<K, K, vespalib::hash<K>, std::equal_to<K>, std::_Identity<K>>;
+ hashtable<K, K, vespalib::hash<K>, std::equal_to<K>, Identity>;
TEST("require that hashtable<int> can be copied") {
set_hashtable<int> table(100);
diff --git a/vespalib/src/vespa/vespalib/stllike/hash_map.h b/vespalib/src/vespa/vespalib/stllike/hash_map.h
index 0de03cb97ee..5eae4cea55e 100644
--- a/vespalib/src/vespa/vespalib/stllike/hash_map.h
+++ b/vespalib/src/vespa/vespalib/stllike/hash_map.h
@@ -3,6 +3,7 @@
#include "hashtable.h"
#include "hash_fun.h"
+#include "select.h"
namespace vespalib {
@@ -13,7 +14,7 @@ public:
typedef std::pair<K, V> value_type;
typedef K key_type;
typedef V mapped_type;
- using HashTable = hashtable< K, value_type, H, EQ, std::_Select1st< value_type >, M >;
+ using HashTable = hashtable< K, value_type, H, EQ, Select1st<value_type>, M >;
private:
HashTable _ht;
public:
diff --git a/vespalib/src/vespa/vespalib/stllike/hash_map.hpp b/vespalib/src/vespa/vespalib/stllike/hash_map.hpp
index 2ca6b97748f..311a256be76 100644
--- a/vespalib/src/vespa/vespalib/stllike/hash_map.hpp
+++ b/vespalib/src/vespa/vespalib/stllike/hash_map.hpp
@@ -3,6 +3,7 @@
#include "hash_map_insert.hpp"
#include "hashtable.hpp"
+#include "select.h"
namespace vespalib {
@@ -68,11 +69,11 @@ hash_map<K, V, H, EQ, M>::getMemoryUsed() const
#define VESPALIB_HASH_MAP_INSTANTIATE_H_E_M(K, V, H, E, M) \
template class vespalib::hash_map<K, V, H, E, M>; \
- template class vespalib::hashtable<K, std::pair<K,V>, H, E, std::_Select1st<std::pair<K,V>>, M>; \
- template vespalib::hashtable<K, std::pair<K,V>, H, E, std::_Select1st<std::pair<K,V>>, M>::insert_result \
- vespalib::hashtable<K, std::pair<K,V>, H, E, std::_Select1st<std::pair<K,V>>, M>::insert(std::pair<K,V> &&); \
- template vespalib::hashtable<K, std::pair<K,V>, H, E, std::_Select1st<std::pair<K,V>>, M>::insert_result \
- vespalib::hashtable<K, std::pair<K,V>, H, E, std::_Select1st<std::pair<K,V>>, M>::insertInternal(std::pair<K,V> &&); \
+ template class vespalib::hashtable<K, std::pair<K,V>, H, E, vespalib::Select1st<std::pair<K,V>>, M>; \
+ template vespalib::hashtable<K, std::pair<K,V>, H, E, vespalib::Select1st<std::pair<K,V>>, M>::insert_result \
+ vespalib::hashtable<K, std::pair<K,V>, H, E, vespalib::Select1st<std::pair<K,V>>, M>::insert(std::pair<K,V> &&); \
+ template vespalib::hashtable<K, std::pair<K,V>, H, E, vespalib::Select1st<std::pair<K,V>>, M>::insert_result \
+ vespalib::hashtable<K, std::pair<K,V>, H, E, vespalib::Select1st<std::pair<K,V>>, M>::insertInternal(std::pair<K,V> &&); \
template class vespalib::Array<vespalib::hash_node<std::pair<K,V>>>;
#define VESPALIB_HASH_MAP_INSTANTIATE_H_E(K, V, H, E) \
diff --git a/vespalib/src/vespa/vespalib/stllike/hash_set.h b/vespalib/src/vespa/vespalib/stllike/hash_set.h
index 7a2db4735aa..919e5e8c47f 100644
--- a/vespalib/src/vespa/vespalib/stllike/hash_set.h
+++ b/vespalib/src/vespa/vespalib/stllike/hash_set.h
@@ -3,6 +3,7 @@
#include "hashtable.h"
#include "hash_fun.h"
+#include "identity.h"
#include <initializer_list>
namespace vespalib {
@@ -11,7 +12,7 @@ template< typename K, typename H = vespalib::hash<K>, typename EQ = std::equal_t
class hash_set
{
private:
- using HashTable = hashtable< K, K, H, EQ, std::_Identity<K>, M>;
+ using HashTable = hashtable< K, K, H, EQ, Identity, M>;
HashTable _ht;
public:
typedef typename HashTable::iterator iterator;
diff --git a/vespalib/src/vespa/vespalib/stllike/hash_set.hpp b/vespalib/src/vespa/vespalib/stllike/hash_set.hpp
index 814c96a3c85..19114798806 100644
--- a/vespalib/src/vespa/vespalib/stllike/hash_set.hpp
+++ b/vespalib/src/vespa/vespalib/stllike/hash_set.hpp
@@ -3,6 +3,7 @@
#include "hash_set_insert.hpp"
#include "hashtable.hpp"
+#include "identity.h"
namespace vespalib {
@@ -84,11 +85,11 @@ hash_set<K, H, EQ, M>::insert(K &&value) {
#define VESPALIB_HASH_SET_INSTANTIATE(K) \
template class vespalib::hash_set<K>; \
- template class vespalib::hashtable<K, K, vespalib::hash<K>, std::equal_to<>, std::_Identity<K>>; \
+ template class vespalib::hashtable<K, K, vespalib::hash<K>, std::equal_to<>, vespalib::Identity>; \
template class vespalib::Array<vespalib::hash_node<K>>;
#define VESPALIB_HASH_SET_INSTANTIATE_H(K, H) \
template class vespalib::hash_set<K, H>; \
- template class vespalib::hashtable<K, K, H, std::equal_to<>, std::_Identity<K>>; \
+ template class vespalib::hashtable<K, K, H, std::equal_to<>, vespalib::Identity>; \
template class vespalib::Array<vespalib::hash_node<K>>;
diff --git a/vespalib/src/vespa/vespalib/stllike/identity.h b/vespalib/src/vespa/vespalib/stllike/identity.h
new file mode 100644
index 00000000000..06019fb4690
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/stllike/identity.h
@@ -0,0 +1,18 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#pragma once
+
+#include <utility>
+
+namespace vespalib {
+
+// Functor which returns its argument unchanged.
+// Functionally identical to C++20's std::identity
+// TODO remove and replace with std::identity once it is available.
+struct Identity {
+ template <typename T>
+ constexpr T&& operator()(T&& v) const noexcept {
+ return std::forward<T>(v);
+ }
+};
+
+}
diff --git a/vespalib/src/vespa/vespalib/stllike/select.h b/vespalib/src/vespa/vespalib/stllike/select.h
new file mode 100644
index 00000000000..28bcd6a01fc
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/stllike/select.h
@@ -0,0 +1,17 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#pragma once
+
+namespace vespalib {
+
+// Convenience functor for extracting the first element of a std::pair (or compatible type)
+template <typename Pair>
+struct Select1st {
+ constexpr typename Pair::first_type& operator()(Pair& p) const noexcept {
+ return p.first;
+ }
+ constexpr const typename Pair::first_type& operator()(const Pair& p) const noexcept {
+ return p.first;
+ }
+};
+
+}