1 // Copyright 2021 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_CONTAINERS_EXTEND_H_ 6 #define BASE_CONTAINERS_EXTEND_H_ 7 8 #include <iterator> 9 #include <vector> 10 11 namespace base { 12 13 // Append to |dst| all elements of |src| by std::move-ing them out of |src|. 14 // After this operation, |src| will be empty. 15 template <typename T> Extend(std::vector<T> & dst,std::vector<T> && src)16void Extend(std::vector<T>& dst, std::vector<T>&& src) { 17 dst.insert(dst.end(), std::make_move_iterator(src.begin()), 18 std::make_move_iterator(src.end())); 19 src.clear(); 20 } 21 22 // Append to |dst| all elements of |src| by copying them out of |src|. |src| is 23 // not changed. 24 template <typename T> Extend(std::vector<T> & dst,const std::vector<T> & src)25void Extend(std::vector<T>& dst, const std::vector<T>& src) { 26 dst.insert(dst.end(), src.begin(), src.end()); 27 } 28 29 } // namespace base 30 31 #endif // BASE_CONTAINERS_EXTEND_H_ 32