From: Kefu Chai Date: Mon, 21 Dec 2020 17:07:37 +0000 (+0800) Subject: include/denc: use pair in range-based for loop X-Git-Tag: v16.1.0~175^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F38678%2Fhead;p=ceph.git include/denc: use pair in range-based for loop map::value_type is pair, so if we use range-based for loop when iterating through a map, we should use pair instead of pair, the latter also compiles, but it might create a temporary object of pair from pair. GCC-11 complains at seeing this: ../src/include/denc.h:1002:21: warning: loop variable ‘e’ of type ‘const T&’ {aka ‘const std::pair&’} binds to a tem\ porary constructed from type ‘const std::pair’ [-Wrange-loop-constru ct] 1002 | for (const T& e : s) { | ^ this change * use the value_type of container in `maplike_details`, so we can avoid the overhead of creating temporay objects when encoding a map * define denc_traits for std::pair as well, so the elements of a map can be encoded using denc facility Signed-off-by: Kefu Chai --- diff --git a/src/include/denc.h b/src/include/denc.h index 402c5a47169b..266121bd20cd 100644 --- a/src/include/denc.h +++ b/src/include/denc.h @@ -877,7 +877,7 @@ struct denc_traits { template struct denc_traits< std::pair, - std::enable_if_t && denc_supported>> { + std::enable_if_t> && denc_supported>> { typedef denc_traits a_traits; typedef denc_traits b_traits; @@ -909,14 +909,14 @@ struct denc_traits< } static void decode(std::pair& v, ceph::buffer::ptr::const_iterator& p, uint64_t f=0) { - denc(v.first, p, f); + denc(const_cast&>(v.first), p, f); denc(v.second, p, f); } template static std::enable_if_t decode(std::pair& v, ceph::buffer::list::const_iterator& p, uint64_t f = 0) { - denc(v.first, p); + denc(const_cast&>(v.first), p); denc(v.second, p); } }; @@ -1217,8 +1217,7 @@ struct denc_traits< namespace _denc { template struct maplike_details : public container_details_base { - using T = std::pair; + using T = typename Container::value_type; template static void insert(Container& c, Args&& ...args) { c.emplace_hint(c.cend(), std::forward(args)...);