From dcd6d70eef92f2574ff2908f76915c278796ce6f Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Tue, 9 Jan 2018 23:28:37 -0500 Subject: [PATCH] types: Output of arbitrary std::tuples Again, using ceph::for_each Signed-off-by: Adam C. Emerson --- src/include/types.h | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/include/types.h b/src/include/types.h index a5d533530e078..178051d323a2d 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -101,8 +101,10 @@ template inline ostream& operator<<(ostream& out, const vector& v); template inline ostream& operator<<(ostream& out, const deque& v); -template -inline ostream& operator<<(ostream&out, const boost::tuple &t); +template +inline ostream& operator<<(ostream& out, const std::tuple &t); +template +inline ostream& operator<<(ostream& out, const boost::tuple &t); template inline ostream& operator<<(ostream& out, const list& ilist); template @@ -144,9 +146,21 @@ inline ostream& operator<<(ostream& out, const deque& v) { return out; } -template -inline ostream& operator<<(ostream&out, const boost::tuple &t) { - out << boost::get<0>(t) <<"," << boost::get<1>(t) << "," << boost::get<2>(t); +template +inline ostream& operator<<(ostream& out, const boost::tuple &t) { + return out << boost::get<0>(t) << "," + << boost::get<1>(t) << "," + << boost::get<2>(t); +} + +template +inline ostream& operator<<(ostream& out, const std::tuple &t) { + auto f = [n = sizeof...(Ts), i = 0, &out](const auto& e) mutable { + out << e; + if (++i != n) + out << ","; + }; + ceph::for_each(t, f); return out; } -- 2.39.5