From 70487bbc480c8460e04a77623c01d31af28e5c4b Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Tue, 9 Jan 2018 17:03:03 -0500 Subject: [PATCH] denc: Remove unneeded enable_ifs The idiom ``` template static enable_if_t ``` Exists to force SFINAE dependent on some aspect of T on functions that are themselves members of a template parameterized on T. Without some other expression conjoined to it, this construct is just noise. Also replace the reserve switch with constexpr if. Signed-off-by: Adam C. Emerson --- src/include/denc.h | 134 +++++++++++++++++---------------------------- 1 file changed, 51 insertions(+), 83 deletions(-) diff --git a/src/include/denc.h b/src/include/denc.h index b4b133a8460d6..36ef8b7ae110d 100644 --- a/src/include/denc.h +++ b/src/include/denc.h @@ -292,23 +292,20 @@ template struct ExtType { }; template -struct ExtType || - std::is_same_v>> { +struct ExtType || + std::is_same_v>> { using type = __le16; }; template -struct ExtType || - std::is_same_v>> { +struct ExtType || + std::is_same_v>> { using type = __le32; }; template -struct ExtType || - std::is_same_v>> { +struct ExtType || + std::is_same_v>> { using type = __le64; }; @@ -321,14 +318,13 @@ using ExtType_t = typename ExtType::type; } // namespace _denc template -struct denc_traits>>> +struct denc_traits>>> { static constexpr bool supported = true; static constexpr bool featured = false; static constexpr bool bounded = true; static constexpr bool need_contiguous = false; - using etype = typename _denc::ExtType::type; + using etype = _denc::ExtType_t; static void bound_encode(const T &o, size_t& p, uint64_t f=0) { p += sizeof(etype); } @@ -681,20 +677,20 @@ public: static void encode(const value_type& s, buffer::list::contiguous_appender& p, uint64_t f=0) { - ::denc((uint32_t)s.size(), p); + denc((uint32_t)s.size(), p); memcpy(p.get_pos_add(s.size()), s.data(), s.size()); } static void decode(value_type& s, buffer::ptr::iterator& p, uint64_t f=0) { uint32_t len; - ::denc(len, p); + denc(len, p); decode_nohead(len, s, p); } static void decode(value_type& s, buffer::list::iterator& p) { uint32_t len; - ::denc(len, p); + denc(len, p); s.clear(); p.copy(len, s); } @@ -725,17 +721,17 @@ struct denc_traits { } static void encode(const bufferptr& v, buffer::list::contiguous_appender& p, uint64_t f=0) { - ::denc((uint32_t)v.length(), p); + denc((uint32_t)v.length(), p); p.append(v); } static void decode(bufferptr& v, buffer::ptr::iterator& p, uint64_t f=0) { uint32_t len; - ::denc(len, p); + denc(len, p); v = p.get_ptr(len); } static void decode(bufferptr& v, buffer::list::iterator& p) { uint32_t len; - ::denc(len, p); + denc(len, p); bufferlist s; p.copy(len, s); if (len) { @@ -761,18 +757,18 @@ struct denc_traits { } static void encode(const bufferlist& v, buffer::list::contiguous_appender& p, uint64_t f=0) { - ::denc((uint32_t)v.length(), p); + denc((uint32_t)v.length(), p); p.append(v); } static void decode(bufferlist& v, buffer::ptr::iterator& p, uint64_t f=0) { uint32_t len; - ::denc(len, p); + denc(len, p); v.clear(); v.push_back(p.get_ptr(len)); } static void decode(bufferlist& v, buffer::list::iterator& p) { uint32_t len; - ::denc(len, p); + denc(len, p); v.clear(); p.copy(len, v); } @@ -795,8 +791,7 @@ struct denc_traits { template struct denc_traits< std::pair, - std::enable_if_t::supported && - denc_traits::supported>> { + std::enable_if_t && denc_supported>> { typedef denc_traits a_traits; typedef denc_traits b_traits; @@ -806,9 +801,7 @@ struct denc_traits< static constexpr bool need_contiguous = (a_traits::need_contiguous || b_traits::need_contiguous); - template - static std::enable_if_t - bound_encode(const std::pair& v, size_t& p, uint64_t f = 0) { + static void bound_encode(const std::pair& v, size_t& p, uint64_t f = 0) { if constexpr (featured) { denc(v.first, p, f); denc(v.second, p, f); @@ -818,10 +811,8 @@ struct denc_traits< } } - template - static std::enable_if_t - encode(const std::pair& v, bufferlist::contiguous_appender& p, - uint64_t f = 0) { + static void encode(const std::pair& v, bufferlist::contiguous_appender& p, + uint64_t f = 0) { if constexpr (featured) { denc(v.first, p, f); denc(v.second, p, f); @@ -860,8 +851,7 @@ namespace _denc { static constexpr bool need_contiguous = traits::need_contiguous; template - static std::enable_if_t - bound_encode(const container& s, size_t& p, uint64_t f = 0) { + static void bound_encode(const container& s, size_t& p, uint64_t f = 0) { p += sizeof(uint32_t); if constexpr (traits::bounded) { if (!s.empty()) { @@ -887,8 +877,7 @@ namespace _denc { } template - static std::enable_if_t - encode(const container& s, buffer::list::contiguous_appender& p, + static void encode(const container& s, buffer::list::contiguous_appender& p, uint64_t f = 0) { denc((uint32_t)s.size(), p); if constexpr (traits::featured) { @@ -911,10 +900,8 @@ namespace _denc { } // nohead - template - static std::enable_if_t - encode_nohead(const container& s, buffer::list::contiguous_appender& p, - uint64_t f = 0) { + static void encode_nohead(const container& s, buffer::list::contiguous_appender& p, + uint64_t f = 0) { for (const T& e : s) { if constexpr (traits::featured) { denc(e, p, f); @@ -961,29 +948,21 @@ namespace _denc { static constexpr bool value = decltype( test>(0))::value; }; + template + inline constexpr bool container_has_reserve_v = + container_has_reserve::value; - template::value> - struct reserve_switch; - template - struct reserve_switch { + struct container_details_base { + using T = typename Container::value_type; static void reserve(Container& c, size_t s) { - c.reserve(s); + if constexpr (container_has_reserve_v) { + c.reserve(s); + } } }; - template - struct reserve_switch { - static void reserve(Container& c, size_t s) {} - }; - - template - struct container_details_base : public reserve_switch { - using T = typename Container::value_type; - }; - template struct pushback_details : public container_details_base { template @@ -1083,9 +1062,7 @@ public: static constexpr bool bounded = traits::bounded; static constexpr bool need_contiguous = traits::need_contiguous; - template - static std::enable_if_t - bound_encode(const container& s, size_t& p, uint64_t f = 0) { + static void bound_encode(const container& s, size_t& p, uint64_t f = 0) { if constexpr (traits::bounded) { if constexpr (traits::featured) { size_t elem_size = 0; @@ -1110,9 +1087,7 @@ public: } } - template - static std::enable_if_t - encode(const container& s, buffer::list::contiguous_appender& p, + static void encode(const container& s, buffer::list::contiguous_appender& p, uint64_t f = 0) { for (const auto& e : s) { if constexpr (traits::featured) { @@ -1371,9 +1346,8 @@ struct denc_traits< static constexpr bool bounded = false; static constexpr bool need_contiguous = traits::need_contiguous; - template - static std::enable_if_t - bound_encode(const boost::optional& v, size_t& p, uint64_t f = 0) { + static void bound_encode(const boost::optional& v, size_t& p, + uint64_t f = 0) { p += sizeof(bool); if (v) { if constexpr (featured) { @@ -1384,10 +1358,9 @@ struct denc_traits< } } - template - static std::enable_if_t - encode(const boost::optional& v, bufferlist::contiguous_appender& p, - uint64_t f = 0) { + static void encode(const boost::optional& v, + bufferlist::contiguous_appender& p, + uint64_t f = 0) { denc((bool)v, p); if (v) { if constexpr (featured) { @@ -1424,10 +1397,9 @@ struct denc_traits< } template - static std::enable_if_t - encode_nohead(const boost::optional& v, - bufferlist::contiguous_appender& p, - uint64_t f = 0) { + static void encode_nohead(const boost::optional& v, + bufferlist::contiguous_appender& p, + uint64_t f = 0) { if (v) { if constexpr (featured) { denc(*v, p, f); @@ -1479,9 +1451,8 @@ struct denc_traits< static constexpr bool bounded = false; static constexpr bool need_contiguous = traits::need_contiguous; - template - static std::enable_if_t - bound_encode(const std::optional& v, size_t& p, uint64_t f = 0) { + static void bound_encode(const std::optional& v, size_t& p, + uint64_t f = 0) { p += sizeof(bool); if (v) { if constexpr (featured) { @@ -1492,10 +1463,9 @@ struct denc_traits< } } - template - static std::enable_if_t - encode(const std::optional& v, bufferlist::contiguous_appender& p, - uint64_t f = 0) { + static void encode(const std::optional& v, + bufferlist::contiguous_appender& p, + uint64_t f = 0) { denc((bool)v, p); if (v) { if constexpr (featured) { @@ -1531,11 +1501,9 @@ struct denc_traits< } } - template - static std::enable_if_t - encode_nohead(const std::optional& v, - bufferlist::contiguous_appender& p, - uint64_t f = 0) { + static void encode_nohead(const std::optional& v, + bufferlist::contiguous_appender& p, + uint64_t f = 0) { if (v) { if constexpr (featured) { denc(*v, p, f); -- 2.39.5