In my header file:-
In my source file:-
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?
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);
};
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)
}