aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/lib/gtl/flatset.h
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow/core/lib/gtl/flatset.h')
-rw-r--r--tensorflow/core/lib/gtl/flatset.h17
1 files changed, 15 insertions, 2 deletions
diff --git a/tensorflow/core/lib/gtl/flatset.h b/tensorflow/core/lib/gtl/flatset.h
index f31e3abe41..bb4356e46d 100644
--- a/tensorflow/core/lib/gtl/flatset.h
+++ b/tensorflow/core/lib/gtl/flatset.h
@@ -59,6 +59,10 @@ class FlatSet {
FlatSet(const FlatSet& src) : rep_(src.rep_) {}
+ // Move constructor leaves src in a valid but unspecified state (same as
+ // std::unordered_set).
+ FlatSet(FlatSet&& src) : rep_(std::move(src.rep_)) {}
+
template <typename InputIter>
FlatSet(InputIter first, InputIter last, size_t N = 1,
const Hash& hf = Hash(), const Eq& eq = Eq())
@@ -75,6 +79,13 @@ class FlatSet {
return *this;
}
+ // Move-assignment operator leaves src in a valid but unspecified state (same
+ // as std::unordered_set).
+ FlatSet& operator=(FlatSet&& src) {
+ rep_.MoveFrom(std::move(src.rep_));
+ return *this;
+ }
+
~FlatSet() {}
void swap(FlatSet& x) { rep_.swap(x.rep_); }
@@ -169,6 +180,7 @@ class FlatSet {
}
std::pair<iterator, bool> insert(const Key& k) { return Insert(k); }
+ std::pair<iterator, bool> insert(Key&& k) { return Insert(std::move(k)); }
template <typename InputIter>
void insert(InputIter first, InputIter last) {
for (; first != last; ++first) {
@@ -265,9 +277,10 @@ class FlatSet {
}
};
- std::pair<iterator, bool> Insert(const Key& k) {
+ template <typename K>
+ std::pair<iterator, bool> Insert(K&& k) {
rep_.MaybeResize();
- auto r = rep_.FindOrInsert(k);
+ auto r = rep_.FindOrInsert(std::forward<K>(k));
const bool inserted = !r.found;
return {iterator(r.b, rep_.limit(), r.index), inserted};
}