Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
template<typename Finalizer, typename Generator, typename... Generators>
auto weighted_one_of_gen(
Finalizer finalizer, Weighted<Generator> head, Weighted<Generators>... tail)
using Out = decltype(finalizer(head.m_value(std::declval<std::mt19937&>())));
using OutGen = std::function<Out(std::mt19937&)>;
auto map_first = [&](auto&& wg) -> Weighted<OutGen>
return Weighted<OutGen>{transform_gen(finalizer, wg.m_value), wg.m_weight};
std::vector<Weighted<OutGen>> weighted_gens{ map_first(head), map_first(tail)... };
auto generator_picker = weighted_choice_gen(weighted_gens);
return [=](std::mt19937& bit_gen)
return generator_picker(bit_gen)(bit_gen);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment