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); } }
std::vector<typename Partial::SolutionT> generate(Partial const & part, Constraint constr) { using SolutionVec = std::vector<typename Partial::SolutionT>; if (part.isFinished(constr)) { SolutionVec result{ part.getSolution() }; return result; } else { Stream<Partial> partList = part.refine(constr); SolutionVec result; forEach(std::move(partList), [&](Partial const & part){ SolutionVec lst = generate(part, constr); std::copy(lst.begin(), lst.end(), std::back_inserter(result)); }); return result; } }