简体   繁体   中英

c++ stl find algo on multimap

std::multimap<size_type,size_type>::iterator it;
std::multimap<size_type,size_type>::iterator itlow = colToRow.lower_bound(cols[i]);
std::multimap<size_type,size_type>::iterator itup = colToRow.upper_bound(cols[i]);

if((it = std::find(itlow,itup,std::pair<size_type,size_type>(cols[i],b))) != itup)

Why does this keep giving me an error, cols[i] and b are both of size type and when I insert into the multimap, it has no problem of inserting it as a pair, how else can this be done?

Thank you,

The error:

/usr/include/c++/4.3/bits/stl_algo.h: In function '_InputIterator std::__find(_InputIterator, _InputIterator, const _Tp&, std::input_iterator_tag) [with _InputIterator = std::_Rb_tree_iterator<std::pair<const unsigned int, unsigned int> >, _Tp = std::pair<unsigned int, unsigned int>]':
/usr/include/c++/4.3/bits/stl_algo.h:3814:   instantiated from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = std::_Rb_tree_iterator<std::pair<const unsigned int, unsigned int> >, _Tp = std::pair<unsigned int, unsigned int>]'
SMatrix.cpp:286:   instantiated from here
/usr/include/c++/4.3/bits/stl_algo.h:151: error: no match for 'operator==' in '__first.std::_Rb_tree_iterator<_Tp>::operator* [with _Tp = std::pair<const unsigned int, unsigned int>]() == __val'

The value_type of a multimap<size_type, size_type> is a std::pair<size_type const,size_type> , rather than a std::pair<size_type,size_type> .

You are trying to find a std::pair<size_type,size_type> , but this cannot be compared to a std::pair<size_type const,size_type> .

Try:

if((it = std::find(itlow,itup,std::pair<const size_type,size_type>(cols[i],b))) != itup)
//                                      ^^^^^

Due to the hint from this error:

error: no match for 'operator==' in '__first.std::_Rb_tree_iterator<_Tp>::operator* 
    [with _Tp = std::pair<const unsigned int, unsigned int>]() == __val'
//                        ^^^^^^^^^^^^^^^^^^

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