[gdal-dev] Use of std::unique_ptr and auto in new code

Kurt Schwehr schwehr at gmail.com
Wed Dec 13 06:47:49 PST 2017


Here is a range based for replacement of an iterator as a starter for
comments/discussion:

https://trac.osgeo.org/gdal/changeset/41019
<https://www.google.com/url?sa=D&q=https%3A%2F%2Ftrac.osgeo.org%2Fgdal%2Fchangeset%2F41019>

On Tue, Dec 12, 2017 at 7:27 PM, Kurt Schwehr <schwehr at gmail.com> wrote:

> +1 on the range based for
>
> +1 on std::unique_ptr, but ... I think GDAL should stick to these:
>
> - Do not do "using std::unique_ptr;"
> - Do not exposed std::unique_ptr to any public interfaces (for the time
> being)
>
> On Tue, Dec 12, 2017 at 4:06 AM, Even Rouault <even.rouault at spatialys.com>
> wrote:
>
>> > 1. std::unique_ptr
>>
>> >
>>
>> [...]
>>
>> >
>>
>> > Hopefully this will help to reduce the incidence of memory leaks.
>>
>>
>>
>> +1, that's one of the benefits of C++11
>>
>> >
>>
>> > --
>>
>> >
>>
>> > 2. auto
>>
>> >
>>
>> > I'd like to not have to write
>>
>> >
>>
>> > for( std::vector<std::unique_ptr<OGRFeature>>::iterator oIt =
>>
>> > apoMyList.begin();
>>
>> >
>>
>> > and simply write
>>
>> >
>>
>> > for( auto oIt = apoMyList.begin();
>>
>>
>>
>> +1. You could even use range based loop
>>
>>
>>
>> for( auto& olt: apoMyList )
>>
>>
>>
>> (or auto const& depending on what you want to do with it)
>>
>>
>>
>> Even
>>
>>
>>
>> --
>>
>> Spatialys - Geospatial professional services
>>
>> http://www.spatialys.com
>>
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>
>
>
> --
> --
> http://schwehr.org
>



-- 
--
http://schwehr.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20171213/c20c09bc/attachment-0001.html>


More information about the gdal-dev mailing list