I've got two tuples, std::tuple<F1, F2, ..., FN>
, std::tuple<G1, G2, ..., GN>
(or std::tuple<G1>
aka G1
). Is there any way to join these tuples generically into a std::tuple<F1, F2, ..., FN, G1, G2, ..., GN>
if any of the types F1
, F2
, ..., FN
, G1
, G2
, ..., GN
does not have a default constructor, but is movable / swapable?
You can use std::tuple_cat
std::tuple<foo, bar, baz> buzz;
std::tuple<moo, meow, arf> bark;
auto my_cat_tuple = std::tuple_cat(buzz, std::move(bark)); // copy elements of buzz,
// move elements of bark
The above will work if the element types of the tuples are movable or copyable. And it does not require them to be default constructible unless you're doing something like
decltype(std::tuple_cat(buzz, bark)) my_uncatted_yet_tuple; // This will attempt to default construct the tuple elements
my_uncatted_yet_tuple = std::tuple_cat(buzz, std::move(bark));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With