[Development] RFC: more liberal 'auto' rules?
Thiago Macieira
thiago.macieira at intel.com
Mon Dec 7 18:04:00 CET 2015
On Monday 07 December 2015 17:53:41 Olivier Goffart wrote:
> On Monday 7. December 2015 08:28:53 Thiago Macieira wrote:
> > What const is missing? Are you saying it should have been
> >
> > for (const std::pair<const std::string, std::string> &e: stdMap)
>
> Yes.
>
> The value_type of a std::map<Key,T> is std::pair<const Key, T>.
>
> It allows to do this:
>
> // add "foobar" to all the entries
> for (auto &e: stdMap)
> e.second += "foobar";
>
> But it does not allow to change the key because that cannot be changed via
> an iterator.
Ah, right, this is a *mutating* iterator. Sorry, I missed that fact.
I was thinking of the usual read-only iteration that we get from foreach.
Mutating with a range for is something I've never done.
> > If so, I consider that an API defect in std::map
>
> Quite the contrary.
I stand corrected.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Development
mailing list