From 98572fba64141287f116e21b2db913f6ff6a7168 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Tue, 9 Jan 2018 23:29:06 -0500 Subject: [PATCH] denc: Clean up tuples even more Signed-off-by: Adam C. Emerson --- src/include/denc.h | 74 ++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 46 deletions(-) diff --git a/src/include/denc.h b/src/include/denc.h index 9b291736899..325bada52bf 100644 --- a/src/include/denc.h +++ b/src/include/denc.h @@ -46,6 +46,8 @@ #include "buffer.h" #include "byteorder.h" +#include "common/convenience.h" + template struct denc_traits { static constexpr bool supported = false; @@ -1120,46 +1122,6 @@ private: "Zero-length tuples are not supported."); using container = std::tuple; - template - static std::enable_if_t::featured> - bound_encode_helper(const U& s, size_t& p, - std::uint64_t f, - std::index_sequence) { - (denc(std::get(s), p, f), ..., void()); - } - template - static std::enable_if_t::featured> - bound_encode_helper(const U& s, size_t& p, - std::index_sequence) { - (denc(std::get(s), p), ..., void()); - } - - template - static std::enable_if_t::featured> - encode_helper(const U& s, buffer::list::contiguous_appender& p, - std::uint64_t f, - std::index_sequence) { - (denc(std::get(s), p, f), ..., void()); - } - template - static std::enable_if_t::featured> - encode_helper(const U& s, buffer::list::contiguous_appender& p, - std::index_sequence) { - (denc(std::get(s), p), ..., void()); - } - - template - static void decode_helper(container& s, buffer::ptr::iterator& p, - std::index_sequence) { - (denc(std::get(s), p), ..., void()); - } - - template - static std::enable_if_t::need_contiguous> - decode_helper(U& s, buffer::list::iterator& p, std::index_sequence) { - (denc(std::get(s), p), ..., void()); - } - public: static constexpr bool supported = true; @@ -1171,33 +1133,53 @@ public: template static std::enable_if_t::featured> bound_encode(const container& s, size_t& p, uint64_t f) { - bound_encode_helper(s, p, f, std::index_sequence_for{}); + ceph::for_each(s, [&p, f] (const auto& e) { + if constexpr (denc_traits>::featured) { + denc(e, p, f); + } else { + denc(e, p); + } + }); } template static std::enable_if_t::featured> bound_encode(const container& s, size_t& p) { - bound_encode_helper(s, p, std::index_sequence_for{}); + ceph::for_each(s, [&p] (const auto& e) { + denc(e, p); + }); } template static std::enable_if_t::featured> encode(const container& s, buffer::list::contiguous_appender& p, uint64_t f) { - encode_helper(s, p, f, std::index_sequence_for{}); + ceph::for_each(s, [&p, f] (const auto& e) { + if constexpr (denc_traits>::featured) { + denc(e, p, f); + } else { + denc(e, p); + } + }); } template static std::enable_if_t::featured> encode(const container& s, buffer::list::contiguous_appender& p) { - encode_helper(s, p, std::index_sequence_for{}); + ceph::for_each(s, [&p] (const auto& e) { + denc(e, p); + }); } static void decode(container& s, buffer::ptr::iterator& p, uint64_t f = 0) { - decode_helper(s, p, std::index_sequence_for{}); + ceph::for_each(s, [&p] (auto& e) { + denc(e, p); + }); } template static std::enable_if_t::need_contiguous> decode(container& s, buffer::list::iterator& p, uint64_t f = 0) { - decode_helper(s, p, std::index_sequence_for{}); + ceph::for_each(s, [&p] (auto& e) { + denc(e, p); + }); } };