octave-maintainers
[Top][All Lists]
Advanced

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

Re: Using 'auto' to replace extremely long typedefs


From: John W. Eaton
Subject: Re: Using 'auto' to replace extremely long typedefs
Date: Sat, 11 Jun 2016 14:54:14 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.5.0

On 06/10/2016 10:34 PM, Jordi GutiƩrrez Hermoso wrote:
On Fri, 2016-06-10 at 17:35 -0700, Rik wrote:
jwe,

Since we're using bits and pieces of C++11, do you object to replacing some
really long typedefs with the auto keyword?

An example from dynamic-ld.cc:

   typedef std::list<octave::dynamic_library>::const_iterator const_iterator;

coupled with

   for (const_iterator p = lib_list.begin (); p != lib_list.end (); p++)

This could be shortened to the single for statement

   for (auto p = lib_list.cbegin (); p != lib_list.cend (); p++)

Actually, a range loop can shorten this even more:

     for(const auto& p; lib_list)

but the body of the loop needs to be modified, as p is no longer a
pointer but a const reference to the element itself.

Yes, either seems like an improvement to me.

I think the syntax for the range loop uses a colon, not a semicolon. Also, there appear to be other possibilities for element types and initializers:

  http://en.cppreference.com/w/cpp/language/range-for

jwe




reply via email to

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