The following code example is taken from the book
C++20 - The Complete Guide
by Nicolai M. Josuttis,
Leanpub, 2021
The code is licensed under a
Creative Commons Attribution 4.0 International License.
// raw code
#include <vector>
#include <ranges>
#include <algorithm>
#include <array>
template<std::ranges::input_range T>
consteval auto mergeValues(T rg, auto... vals)
{
// create compile-time vector from passed range:
std::vector<std::ranges::range_value_t<T>> v{std::ranges::begin(rg),
std::ranges::end(rg)};
(... , v.push_back(vals)); // merge all passed parameters
std::ranges::sort(v); // sort all elements
// return extended collection as array:
constexpr auto sz = std::ranges::size(rg) + sizeof...(vals);
std::array<std::ranges::range_value_t<T>, sz> arr{};
std::ranges::copy(v, arr.begin());
return arr;
}