Transforming a Variant
14 May 2020Q: How do I transform a variant<X, Y, Z>
V
into variant<vector<X>, vector<Y>, vector<Z>>
?
A: Use mp_transform<std::vector, V>
.
Q: And what if I want to use my own allocator A
, that is, want variant<vector<X, A>, vector<Y, A>, vector<Z, A>>
?
A: Use mp_transform_q<mp_bind_back<std::vector, A>, V>
.
Q: But my allocator is a template. How about variant<vector<X, A<X>>, vector<Y, A<Y>>, vector<Z, A<Z>>>
?
A: Use mp_transform<std::vector, V, mp_transform<A, V>>
.
Q: Does Mp11 answer every question with a cryptic one liner?
A: Yes.