MasTasZ
MasTasZ

Reputation: 1

Transform range-based for normal loop

for (const auto & rRec : m_map_handshake)
    {
        if (rRec.second->GetHostName() == inet_ntoa(c_rSockAddr.sin_addr))
        {
                return true;
        }
    }

I have code like this, but range-based for loop won't work on old gcc compiler.

Is there any way to work aroung this? I am not an expert on C++

Upvotes: 0

Views: 72

Answers (1)

Wander3r
Wander3r

Reputation: 1881

You can use a normal for loop. Looks like it's std::map. Use iterator to traverse the elements and match the condition.

for(const <map-type>::iterator it = m_map_handshake.begin(); it != m_map_handshake.end();++it){
        if (it->second->GetHostName() == inet_ntoa(c_rSockAddr.sin_addr))
        {
                return true;
        }
}

Here <map-type> will be the type of m_map_handshake.

Upvotes: 3

Related Questions