//******************************************************** // The following code example is taken from the book // C++20 - The Complete Guide // by Nicolai M. Josuttis (www.josuttis.com) // http://www.cppstd20.com // // The code is licensed under a // Creative Commons Attribution 4.0 International License // http://creativecommons.org/licenses/by/4.0/ //******************************************************** #include #include #include #include template consteval auto mergeValuesSz(T rg, auto... vals) { // create compile-time vector from passed range: std::vector> 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 and its size: constexpr auto maxSz = std::ranges::size(rg) + sizeof...(vals); std::array, maxSz> arr{}; auto res = std::ranges::unique_copy(v, arr.begin()); return std::pair{arr, res.out - arr.begin()}; }