diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2019-12-05 16:10:23 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2019-12-17 09:43:58 (GMT) |
commit | a38d04c0764b3550bd7d17b659945a38c1368f1e (patch) | |
tree | 67c5c928c47121a6646b5a666fe2a496c446b21f /Utilities/std/cmext/algorithm | |
parent | d082d0e109257ea2f1adce278658fa825a3f08a2 (diff) | |
download | CMake-a38d04c0764b3550bd7d17b659945a38c1368f1e.zip CMake-a38d04c0764b3550bd7d17b659945a38c1368f1e.tar.gz CMake-a38d04c0764b3550bd7d17b659945a38c1368f1e.tar.bz2 |
Refactoring: introduce header cmext/algorithm with append functions
Diffstat (limited to 'Utilities/std/cmext/algorithm')
-rw-r--r-- | Utilities/std/cmext/algorithm | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Utilities/std/cmext/algorithm b/Utilities/std/cmext/algorithm new file mode 100644 index 0000000..609860c --- /dev/null +++ b/Utilities/std/cmext/algorithm @@ -0,0 +1,52 @@ +// -*-c++-*- +// vim: set ft=cpp: + +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmext_algorithm +#define cmext_algorithm + +#include <algorithm> +#include <iterator> +#include <memory> +#include <utility> +#include <vector> + +#include <cm/type_traits> +#include <cmext/iterator> + +namespace cm { + +template <typename T> +void append(std::vector<std::unique_ptr<T>>& v, + std::vector<std::unique_ptr<T>>&& r) +{ + std::transform(r.begin(), r.end(), std::back_inserter(v), + [](std::unique_ptr<T>& item) { return std::move(item); }); + r.clear(); +} + +template <typename T> +void append(std::vector<T*>& v, std::vector<std::unique_ptr<T>> const& r) +{ + std::transform(r.begin(), r.end(), std::back_inserter(v), + [](const std::unique_ptr<T>& item) { return item.get(); }); +} + +template <typename T, typename InputIt, + cm::enable_if_t<cm::is_input_iterator<InputIt>::value, int> = 0> +void append(std::vector<T>& v, InputIt first, InputIt last) +{ + v.insert(v.end(), first, last); +} + +template <typename T, typename Range, + cm::enable_if_t<cm::is_input_range<Range>::value, int> = 0> +void append(std::vector<T>& v, Range const& r) +{ + v.insert(v.end(), r.begin(), r.end()); +} + +} // namespace cm + +#endif |