Assune tuple suld be output in a comma-separated form:
template <typename TupleT, std::size_t... Is>
void printTupleImp(const TupleT& tp, std::index_sequence<Is...>) {
size_t index = 0;
std::cout << "(";
( ((index++ > 0 ? (std::cout << ", ", true) : true),
void(std::cout << std::get<Is>(tp))), ... );
std::cout << ")";
}
template <typename TupleT, std::size_t TupSize = std::tuple_size_v<TupleT>>
void printTuple(const TupleT& tp) {
printTupleImp(tp, std::make_index_sequence<TupSize>{});
}
int main() {
std::tuple tp { 10, 20, "hello"};
printTuple(tp);
}
It looks like optimization of foldexpression went quite efficiently Compiler Explorer.
Isthere a way to do the same using solely {fmt} and not doing it by outputing to an ostream first, like here?