From 8e877e0d31272f1de8413b5da9581cf7bfc3c559 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Tue, 9 Jan 2018 13:11:10 -0500 Subject: [PATCH] denc: Unbreak Clang support We were using an enable_if idiom that Clang rejects as an illicit narrowing conversion. Signed-off-by: Adam C. Emerson --- src/include/denc.h | 249 +++++++++++++++++++++++---------------------- 1 file changed, 127 insertions(+), 122 deletions(-) diff --git a/src/include/denc.h b/src/include/denc.h index b07e2ed3331..fdc058a9725 100644 --- a/src/include/denc.h +++ b/src/include/denc.h @@ -223,34 +223,39 @@ struct denc_traits { // --------------------------------------------------------------------- // raw types namespace _denc { - template struct is_any_of : std::false_type - {}; - template - struct is_any_of : std::conditional< - std::is_same::value, - std::true_type, - is_any_of>::type - {}; - template struct underlying_type { - using type = T; - }; - template struct underlying_type< - T, typename std::enable_if::value>::type> { - using type = typename std::underlying_type::type; - }; +template +struct is_any_of : std::false_type {}; +template +struct is_any_of : std::conditional< + std::is_same::value, + std::true_type, + is_any_of>::type +{}; +template +inline constexpr bool is_any_of_v = is_any_of::value; + +template struct underlying_type { + using type = T; +}; +template +struct underlying_type>> { + using type = std::underlying_type_t; +}; +template +using underlying_type_t = typename underlying_type::type; } template struct denc_traits< T, - typename std::enable_if< - _denc::is_any_of::type, - ceph_le64, ceph_le32, ceph_le16, uint8_t + std::enable_if_t< + _denc::is_any_of_v<_denc::underlying_type_t, + ceph_le64, ceph_le32, ceph_le16, uint8_t #ifndef _CHAR_IS_SIGNED - , int8_t + , int8_t #endif - >::value>::type> { + >>> { static constexpr bool supported = true; static constexpr bool featured = false; static constexpr bool bounded = true; @@ -290,36 +295,38 @@ template struct ExtType { using type = void; }; -template struct ExtType< - T, - typename std::enable_if::value || - std::is_same::value>::type> { +template +struct ExtType || + std::is_same_v>> { using type = __le16; }; -template struct ExtType< - T, - typename std::enable_if::value || - std::is_same::value>::type> { +template +struct ExtType || + std::is_same_v>> { using type = __le32; }; -template struct ExtType< - T, - typename std::enable_if::value || - std::is_same::value>::type> { +template +struct ExtType || + std::is_same_v>> { using type = __le64; }; -template<> struct ExtType { +template<> +struct ExtType { using type = uint8_t; }; +template +using ExtType_t = typename ExtType::type; } // namespace _denc template -struct denc_traits< - T, - typename std::enable_if::type>::value>::type> +struct denc_traits>>> { static constexpr bool supported = true; static constexpr bool featured = false; @@ -566,8 +573,8 @@ inline void denc_lba(uint64_t& v, bufferptr::iterator& p) { // denc top-level methods that call into denc_traits methods template> -inline typename std::enable_if::type denc( +inline std::enable_if_t denc( const T& o, size_t& p, uint64_t f=0) @@ -575,8 +582,8 @@ inline typename std::enable_if> -inline typename std::enable_if::type denc( +inline std::enable_if_t denc( const T& o, size_t& p, uint64_t f) @@ -585,8 +592,8 @@ inline typename std::enable_if> -inline typename std::enable_if::type denc( +inline std::enable_if_t denc( const T& o, buffer::list::contiguous_appender& p, uint64_t features=0) @@ -594,8 +601,8 @@ inline typename std::enable_if> -inline typename std::enable_if::type denc( +inline std::enable_if_t denc( const T& o, buffer::list::contiguous_appender& p, uint64_t features) @@ -604,8 +611,8 @@ inline typename std::enable_if> -inline typename std::enable_if::type denc( +inline std::enable_if_t denc( T& o, buffer::ptr::iterator& p, uint64_t features=0) @@ -613,8 +620,8 @@ inline typename std::enable_if> -inline typename std::enable_if::type denc( +inline std::enable_if_t denc( T& o, buffer::ptr::iterator& p, uint64_t features=0) @@ -623,34 +630,32 @@ inline typename std::enable_if - struct has_legacy_denc : std::false_type - {}; - template - struct has_legacy_denc() - .decode(std::declval()))> : std::true_type - { - static void decode(T& v, bufferlist::iterator& p) { - v.decode(p); - } - }; - template - struct has_legacy_denc::need_contiguous>::type> : std::true_type - { - static void decode(T& v, bufferlist::iterator& p) { - denc_traits::decode(v, p); - } - }; +template +struct has_legacy_denc : std::false_type {}; +template +struct has_legacy_denc() + .decode(std::declval< + bufferlist::iterator&>()))> + : std::true_type { + static void decode(T& v, bufferlist::iterator& p) { + v.decode(p); + } +}; +template +struct has_legacy_denc::need_contiguous>> : std::true_type { + static void decode(T& v, bufferlist::iterator& p) { + denc_traits::decode(v, p); + } +}; } template, typename has_legacy_denc=_denc::has_legacy_denc> -inline typename std::enable_if::type denc( +inline std::enable_if_t denc( T& o, buffer::list::iterator& p) { @@ -794,8 +799,8 @@ struct denc_traits { template struct denc_traits< std::pair, - typename std::enable_if::supported && - denc_traits::supported>::type> { + std::enable_if_t::supported && + denc_traits::supported>> { typedef denc_traits a_traits; typedef denc_traits b_traits; @@ -806,7 +811,7 @@ struct denc_traits< b_traits::need_contiguous); template - static typename std::enable_if::type + static std::enable_if_t bound_encode(const std::pair& v, size_t& p, uint64_t f = 0) { if constexpr (featured) { denc(v.first, p, f); @@ -818,7 +823,7 @@ struct denc_traits< } template - static typename std::enable_if::type + static std::enable_if_t encode(const std::pair& v, bufferlist::contiguous_appender& p, uint64_t f = 0) { if constexpr (featured) { @@ -835,7 +840,7 @@ struct denc_traits< denc(v.second, p, f); } template - static typename std::enable_if::type + static std::enable_if_t decode(std::pair& v, buffer::list::iterator& p, uint64_t f = 0) { denc(v.first, p); @@ -859,7 +864,7 @@ namespace _denc { static constexpr bool need_contiguous = traits::need_contiguous; template - static typename std::enable_if::type + static std::enable_if_t bound_encode(const container& s, size_t& p, uint64_t f = 0) { p += sizeof(uint32_t); if constexpr (traits::bounded) { @@ -886,7 +891,7 @@ namespace _denc { } template - static typename std::enable_if::type + static std::enable_if_t encode(const container& s, buffer::list::contiguous_appender& p, uint64_t f = 0) { denc((uint32_t)s.size(), p); @@ -902,7 +907,7 @@ namespace _denc { decode_nohead(num, s, p, f); } template - static typename std::enable_if::type + static std::enable_if_t decode(container& s, buffer::list::iterator& p) { uint32_t num; denc(num, p); @@ -911,7 +916,7 @@ namespace _denc { // nohead template - static typename std::enable_if::type + static std::enable_if_t encode_nohead(const container& s, buffer::list::contiguous_appender& p, uint64_t f = 0) { for (const T& e : s) { @@ -933,7 +938,7 @@ namespace _denc { } } template - static typename std::enable_if::type + static std::enable_if_t decode_nohead(size_t num, container& s, buffer::list::iterator& p) { s.clear(); @@ -995,7 +1000,7 @@ namespace _denc { template struct denc_traits< std::list, - typename std::enable_if::supported>::type> + typename std::enable_if_t::supported>> : public _denc::container_base>, T, Ts...> {}; @@ -1003,7 +1008,7 @@ struct denc_traits< template struct denc_traits< std::vector, - typename std::enable_if::supported>::type> + typename std::enable_if_t::supported>> : public _denc::container_base>, T, Ts...> {}; @@ -1022,7 +1027,7 @@ namespace _denc { template struct denc_traits< std::set, - typename std::enable_if::supported>::type> + std::enable_if_t::supported>> : public _denc::container_base>, T, Ts...> {}; @@ -1030,7 +1035,7 @@ struct denc_traits< template struct denc_traits< boost::container::flat_set, - typename std::enable_if::supported>::type> + std::enable_if_t::supported>> : public _denc::container_base< boost::container::flat_set, _denc::setlike_details>, @@ -1051,8 +1056,8 @@ namespace _denc { template struct denc_traits< std::map, - typename std::enable_if::supported && - denc_traits::supported>::type> + std::enable_if_t::supported && + denc_traits::supported>> : public _denc::container_base>, A, B, Ts...> {}; @@ -1060,8 +1065,8 @@ struct denc_traits< template struct denc_traits< boost::container::flat_map, - typename std::enable_if::supported && - denc_traits::supported>::type> + std::enable_if_t::supported && + denc_traits::supported>> : public _denc::container_base< boost::container::flat_map, _denc::maplike_details struct denc_traits< std::array, - typename std::enable_if::supported>::type> { + std::enable_if_t::supported>> { private: using container = std::array; public: @@ -1083,7 +1088,7 @@ public: static constexpr bool need_contiguous = traits::need_contiguous; template - static typename std::enable_if::type + static std::enable_if_t bound_encode(const container& s, size_t& p, uint64_t f = 0) { if constexpr (traits::bounded) { if constexpr (traits::featured) { @@ -1110,7 +1115,7 @@ public: } template - static typename std::enable_if::type + static std::enable_if_t encode(const container& s, buffer::list::contiguous_appender& p, uint64_t f = 0) { for (const auto& e : s) { @@ -1126,8 +1131,8 @@ public: denc(e, p, f); } template - static typename std::enable_if::type + static std::enable_if_t decode(container& s, buffer::list::iterator& p) { for (auto& e : s) { denc(e, p); @@ -1192,7 +1197,7 @@ namespace _denc { template struct denc_traits< std::tuple, - typename std::enable_if<_denc::tuple_traits::supported>::type> { + std::enable_if_t<_denc::tuple_traits::supported>> { private: static_assert(sizeof...(Ts) > 0, "Zero-length tuples are not supported."); @@ -1303,43 +1308,43 @@ public: template - static typename std::enable_if::type + static std::enable_if_t bound_encode(const container& s, size_t& p) { bound_encode_helper_nfnb(s, p, _denc::build_indices_t{}); } template - static typename std::enable_if::type + static std::enable_if_t bound_encode(const container& s, size_t& p) { bound_encode_helper_nfb(s, p, _denc::build_indices_t{}); } template - static typename std::enable_if::type + static std::enable_if_t bound_encode(const container& s, size_t& p, uint64_t f) { bound_encode_helper_fnb(s, p, _denc::build_indices_t{}); } template - static typename std::enable_if::type + static std::enable_if_t bound_encode(const container& s, size_t& p, uint64_t f) { bound_encode_helper_fb(s, p, _denc::build_indices_t{}); } template - static typename std::enable_if::type + static std::enable_if_t encode(const container& s, buffer::list::contiguous_appender& p) { encode_helper_nf(s, p, _denc::build_indices_t{}); } template - static typename std::enable_if::type + static std::enable_if_t encode(const container& s, buffer::list::contiguous_appender& p, uint64_t f) { encode_helper_f(s, p, f, _denc::build_indices_t{}); @@ -1349,8 +1354,8 @@ public: decode_helper(s, p, _denc::build_indices_t{}); } template - static typename std::enable_if::type + static std::enable_if_t decode(container& s, buffer::list::iterator& p, uint64_t f = 0) { decode_helper(s, p, _denc::build_indices_t{}); } @@ -1362,7 +1367,7 @@ public: template struct denc_traits< boost::optional, - typename std::enable_if::supported>::type> { + std::enable_if_t::supported>> { using traits = denc_traits; static constexpr bool supported = true; @@ -1371,7 +1376,7 @@ struct denc_traits< static constexpr bool need_contiguous = traits::need_contiguous; template - static typename std::enable_if::type + static std::enable_if_t bound_encode(const boost::optional& v, size_t& p, uint64_t f = 0) { p += sizeof(bool); if (v) { @@ -1384,7 +1389,7 @@ struct denc_traits< } template - static typename std::enable_if::type + static std::enable_if_t encode(const boost::optional& v, bufferlist::contiguous_appender& p, uint64_t f = 0) { denc((bool)v, p); @@ -1410,7 +1415,7 @@ struct denc_traits< } template - static typename std::enable_if::type + static std::enable_if_t decode(boost::optional& v, buffer::list::iterator& p) { bool x; denc(x, p); @@ -1423,7 +1428,7 @@ struct denc_traits< } template - static typename std::enable_if::type + static std::enable_if_t encode_nohead(const boost::optional& v, bufferlist::contiguous_appender& p, uint64_t f = 0) { @@ -1718,8 +1723,8 @@ inline std::enable_if_t decode_nohead( _denc_friend(*this, p); \ } \ template \ - friend typename std::enable_if::value || \ - boost::is_same::value>::type \ + friend std::enable_if_t || \ + std::is_same_v> \ _denc_friend(T& v, P& p) #define DENC_FEATURED(Type, v, p, f) \ @@ -1736,8 +1741,8 @@ inline std::enable_if_t decode_nohead( _denc_friend(*this, p, f); \ } \ template \ - friend typename std::enable_if::value || \ - boost::is_same::value>::type \ + friend std::enable_if_t || \ + std::is_same_v> \ _denc_friend(T& v, P& p, uint64_t f) #endif -- 2.39.5