octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: auto and const_iterators


From: John W. Eaton
Subject: Re: auto and const_iterators
Date: Thu, 3 May 2018 01:18:03 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

On 05/02/2018 06:22 PM, Rik wrote:
On 05/02/2018 03:10 PM, John W. Eaton wrote:
On 05/02/2018 06:06 PM, Rik wrote:
On 05/02/2018 02:52 PM, John W. Eaton wrote:

Either solution is OK with me, but I see more lines that remove
const_iterator than iterator.  Are the only ones we have to change the
ones where the object itself is not const but we were accessing elements
with a const_iterator?

That's right.  It's only when we want to confirm to the compiler that the
access should be read-only which is only necessary for a mutable object.
If the entire object is const already then all accesses are necessarily
read-only.

OK, I can fix this, but is there an easier way to find them other than
manually looking at each of the instances where a const_iterator
declaration was replaced by auto?

Unfortunately, I don't think so :(

I pushed the following changeset:

  http://hg.savannah.gnu.org/hgweb/octave/rev/416856765a55

If the object was already const or could be made const (directly, not with a second const reference), I used auto. Otherwise, I made a note that auto could be used in combination with cbegin, cend, crbegin, or crend in the future.

Then I checked and found that cbegin, cend, crbegin, and crend methods were already present in C++11 standard containers. If I understand correctly, C++14 adds a template that can be used to create these from objects that don't provide them. So I also pushed this changeset:

  http://hg.savannah.gnu.org/hgweb/octave/rev/4d7790d9793f

jwe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]