Skip to content

Commit 5e91a05

Browse files
committed
On range insert in tsl::array_map, try to move the value when possible (e.g. if the iterators are std::move_iterator).
1 parent 5c7cb2a commit 5e91a05

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

tsl/array_map.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class array_map {
226226
}
227227

228228
for(auto it = first; it != last; ++it) {
229-
insert(it->first, it->second);
229+
insert_pair(*it);
230230
}
231231
}
232232

@@ -778,6 +778,17 @@ class array_map {
778778
lhs.swap(rhs);
779779
}
780780

781+
private:
782+
template<class U, class V>
783+
void insert_pair(const std::pair<U, V>& value) {
784+
insert(value.first, value.second);
785+
}
786+
787+
template<class U, class V>
788+
void insert_pair(std::pair<U, V>&& value) {
789+
insert(value.first, std::move(value.second));
790+
}
791+
781792
public:
782793
static const size_type MAX_KEY_SIZE = ht::MAX_KEY_SIZE;
783794

0 commit comments

Comments
 (0)