Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3026

Why does MSVC insist on const_iterator ?

$
0
0
In my header file:-
Code:

class DummyBackend {

        // c'tors and stuff

private:
        typedef std::set<DummyPort *> PortIndex;
        PortIndex _ports;

public:
        void function1 (DataType type);
        void function2 (DataType type, PortFlags flags);
};

In my source file:-
Code:

// MSVC seems happy to use std::set::iterator here...

void DummyBackend::function1 (DataType type)
{
        for (PortIndex::iterator i = _ports.begin (); i != _ports.end (); ++i) {
                DummyPort* port = *i;
                if ((port->type () == type) && port->is_input () && port->is_physical ()) {
                        port_names.push_back (port->name ());
                }
        }
}


// But here, it insists on const_iterator...

void DummyBackend::function2 (DataType type, PortFlags flags)
{
        for (PortIndex::const_iterator i = _ports.begin (); i != _ports.end (); ++i) {
                DummyPort* port = *i;
                if ((port->type () == type) && flags == (port->flags () & flags)) {
                        if (call_some_func (port->name ().c_str()))
                                port_names.push_back (port->name ());
                }
        }

        // some more stuff (not involving PortIndex)
}

I'm compiling some open-source code that uses std::set. For function1 it seems happy to use a non-const iterator. But for function 2 MSVC insists on const_iterator. I can't see any obvious reason why. Does it somehow prevent call_some_func() from changing the port name? Can anyone explain?

Viewing all articles
Browse latest Browse all 3026

Trending Articles