0

In the context of a map (template), for the following usage

auto begin = m_map.find(keyBegin);
auto end = m_map.find(keyEnd);

auto p = equal_range(begin,end,val);

        if( !
        (
            p.first == p.second == m_map.end()
        )
  )
{
  //do something
}

The type of keyBegin and keyEnd is unsigned int.

I get the following compilation error:

    error: invalid operands to binary expression 

    ('int' and 'iterator' (aka '__map_iterator<__tree_iterator<std::__1::
    __value_type<unsigned int, char>, std::__1::__tree_node<std::__1::__value_type
<unsigned int, char>, 
    void *> *, long> >'))

    p.first == p.second == m_map.end()

Can someone point out the cause of this error? I am of the understanding that the std::pair<> returned by std::equal_range<> has members of type ForwardIterator for first and second respectively.

user9196120
  • 381
  • 3
  • 9
  • With `std::map`, don't use standalone `equal_range`, use its member function [`equal_range`](http://en.cppreference.com/w/cpp/container/map/equal_range) instead. – Igor Tandetnik Feb 20 '18 at 04:53
  • 2
    `p.first == p.second == m_map.end()` doesn't do what you think it does. It checks whether `m_map.end()` is equal to a boolean value that' the result of `p.first == p.second` comparison. You probably meant something like `p.first == m_map.end() && p.second == m_map.end()` – Igor Tandetnik Feb 20 '18 at 04:57
  • @IgorTandetnik thanks the second suggestion helped. But strangely, I get the error no member by name equal_range for the first suggestion (using the g++ compiler flag std=c++11) – user9196120 Feb 20 '18 at 05:04
  • If you'd like further help, show a [mcve] and a full and complete text of any error messages. – Igor Tandetnik Feb 20 '18 at 05:07

0 Answers0