This is a simple/naive/quickly-written enumeration algorithm. Requires C++20. If you use build2 , just b test to build+run it. I tested with cl and clang (v17) and it seems to works as expected by the simplistic test.