I would like to use set_union() and just scan the output without having to store it.
Something like this (it doesn't compile using g++12.1.0):
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;
int main()
{
vector<int> a = {1,2,3}, b={4,5,6};
ranges::set_union(a, b, [](int i){printf("%d,",i);});
}

You need to supply an "output iterator" for
set_union()to pass elements to. It does not accept a lambda (or other callable type). You can usestd::ostream_iteratorfor this, eg: