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: Jordi Gutiérrez Hermoso
Subject: Re: Using 'auto' to replace extremely long typedefs
Date: Fri, 10 Jun 2016 22:34:06 -0400

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.

- Jordi G. H.





reply via email to

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