当我反向迭代以下代码中的 map 时:

    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--;
    }

我从CMake得到了错误。看来reverse_iteratorutility都可以解释iterator,这会使编译器产生混淆。有没有办法消除这个歧义?
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.

非常感谢你!

最佳答案

您在in comment所指出的某处使用using std::rel_ops,而c++20已弃用。参见 std::rel_ops

一种本地解决的方法是显式调用==

在for循环中,您需要满足以下条件:

versionBatch != self->versionBatches.rend()

而是写为
!(versionBatch == self->versionBatches.rend())

09-27 17:38