简体   繁体   中英

Ambiguous != operator for reverse_iterator

When I reverse iterate a map in the following code:

    std::map<Version, VersionBatch>::reverse_iterator versionBatch = self->versionBatches.rbegin();
    for (; versionBatch != self->versionBatches.rend(); versionBatch++) {
        self->batch[batchIndex] = Reference<MasterBatchData>(new MasterBatchData());
        self->batchStatus[batchIndex] = Reference<MasterBatchStatus>(new MasterBatchStatus());
        fBatches.push_back(distributeWorkloadPerVersionBatch(self, batchIndex, cx, request, versionBatch->second));
        batchIndex--;
    }

I got the error from CMake. It seems the reverse_iterator can be interpreted by both utility and iterator , which causes the compiler to confuse. Is there a way to dis-ambiguous this?

Users/ciuser/jenkins/foundationdb-ci.foundationdb.org/workspace/jobs/prb-cmake-macos/fdbserver/RestoreMaster.actor.cpp:276:22: error: use of overloaded operator '!=' is ambiguous (with operand types 'std::map<Version, VersionBatch>::reverse_iterator' (aka 'reverse_iterator<__map_iterator<__tree_iterator<std::__1::__value_type<long long, VersionBatch>, std::__1::__tree_node<std::__1::__value_type<long long, VersionBatch>, void *> *, long> > >') and 'std::__1::map<long long, VersionBatch, std::__1::less<long long>, std::__1::allocator<std::__1::pair<const long long, VersionBatch> > >::reverse_iterator' (aka 'reverse_iterator<__map_iterator<__tree_iterator<std::__1::__value_type<long long, VersionBatch>, std::__1::__tree_node<std::__1::__value_type<long long, VersionBatch>, void *> *, long> > >'))
                        for(;versionBatch != self->versionBatches.rend();versionBatch++) {
                             ~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/usr/include/c++/v1/utility:218:1: note: candidate function [with _Tp = std::__1::reverse_iterator<std::__1::__map_iterator<std::__1::__tree_iterator<std::__1::__value_type<long long, VersionBatch>, std::__1::__tree_node<std::__1::__value_type<long long, VersionBatch>, void *> *, long> > >]
operator!=(const _Tp& __x, const _Tp& __y)
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/iterator:710:1: note: candidate function [with _Iter1 = std::__1::__map_iterator<std::__1::__tree_iterator<std::__1::__value_type<long long, VersionBatch>, std::__1::__tree_node<std::__1::__value_type<long long, VersionBatch>, void *> *, long> >, _Iter2 = std::__1::__map_iterator<std::__1::__tree_iterator<std::__1::__value_type<long long, VersionBatch>, std::__1::__tree_node<std::__1::__value_type<long long, VersionBatch>, void *> *, long> >]
operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
^
1 error generated.

Thank you very much!

You are using using std::rel_ops somewhere as pointed out in comment , deprecated from . See std::rel_ops .

A way to solve locally is just call == explicitly.

In the for loop you condition you have:

versionBatch != self->versionBatches.rend()

instead write as

!(versionBatch == self->versionBatches.rend())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM