File indexing completed on 2024-05-12 16:59:21

0001 /*
0002  *   SPDX-FileCopyrightText: 2012-2016 Ivan Cukic <ivan.cukic@kde.org>
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #ifndef UTILS_MERGE_INTO_H
0008 #define UTILS_MERGE_INTO_H
0009 
0010 namespace kamd
0011 {
0012 namespace utils
0013 {
0014 template<typename Container>
0015 inline void merge_into(Container &into, const Container &from)
0016 {
0017     typename Container::iterator into_begin = into.begin();
0018     typename Container::iterator into_end = into.end();
0019     typename Container::const_iterator from_begin = from.begin();
0020     typename Container::const_iterator from_end = from.end();
0021 
0022     while (from_begin != from_end) {
0023         while (into_begin != into_end && *from_begin >= *into_begin)
0024             into_begin++;
0025 
0026         into_begin = into.insert(into_begin, *from_begin);
0027         into_begin++;
0028         from_begin++;
0029     }
0030 }
0031 
0032 } // namespace utils
0033 } // namespace kamd
0034 
0035 #endif // UTILS_MERGE_INTO_H