std::vector<typename Partial::SolutionT> generatePar(int depth, Partial const & part, Constraint constr) { using SolutionVec = std::vector<typename Partial::SolutionT>; if (depth == 0) { return generate(part, constr); } else if (part.isFinished(constr)) { SolutionVec result{ part.getSolution() }; return result; } else { Stream<Partial> partList = part.refine(constr); std::vector<std::future<SolutionVec>> futResult; forEach(std::move(partList), [&constr, &futResult, depth](Partial const & part) { std::future<SolutionVec> futLst = std::async([constr, part, depth]() { return generatePar(depth - 1, part, constr); }); futResult.push_back(std::move(futLst)); }); std::vector<SolutionVec> all = when_all_vec(futResult); return concatAll(all); } }
void main() { std::vector<List<Pos>> sol = generatePar(3, PartSol(), 8); for_each(sol.begin(), sol.end(), [](List<Pos> const & queens) { std::cout << queens << std::endl; }); }