]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
include/denc: use pair<const K,V> in range-based for loop 46230/head
authorKefu Chai <kchai@redhat.com>
Mon, 21 Dec 2020 17:07:37 +0000 (01:07 +0800)
committerCasey Bodley <cbodley@redhat.com>
Wed, 11 May 2022 17:33:38 +0000 (13:33 -0400)
commit5507dc6bddb3d2399e274a2641ce889c360c25fc
treefa5ded7eb254e5a36e549136c2e0e615e4e14e76
parentbb906e475d68b74ba2d7d8277f1ee11689153fa1
include/denc: use pair<const K,V> in range-based for loop

map<K,V>::value_type is pair<const K, V>, so if we use range-based for
loop when iterating through a map, we should use pair<const K,V> instead
of pair<K,V>, the latter also compiles, but it might create a temporary
object of pair<K,V> from pair<const K,V>. GCC-11 complains at seeing
this:

../src/include/denc.h:1002:21: warning: loop variable ‘e’ of type ‘const T&’ {aka ‘const std::pair<OSDPerfMetricQuery, OSDPerfMetricReport>&’} binds to a tem\
porary constructed from type ‘const std::pair<const OSDPerfMetricQuery, OSDPerfMetricReport>’ [-Wrange-loop-constru
ct]
 1002 |       for (const T& e : s) {
      |                     ^

this change

* use the value_type of container in `maplike_details<Container>`,
  so we can avoid the overhead of creating temporay objects when
  encoding a map
* define denc_traits for std::pair<const A, B> as well, so the elements
  of a map can be encoded using denc facility

Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit c828ce29400a1eea4b223229b36b3a092eda6139)
src/include/denc.h