[gdal-dev] Use of C++ iterators in API
Andrew Bell
andrew.bell.ia at gmail.com
Wed Apr 11 05:51:55 PDT 2018
On Wed, Apr 11, 2018 at 8:40 AM, Even Rouault <even.rouault at spatialys.com>
wrote:
> On mercredi 11 avril 2018 05:10:53 CEST Kurt Schwehr wrote:
> > The auto&& is really confusing.
>
> A experimentally working alternative with miminal use of '&' is
>
> for( auto poLayer: poDS->GetLayers() ) <-- this is a plain OGRLayer*
> {
> for( auto& poFeature: *poLayer ) <-- this is a
> unique_ptr<OGRFeature> so needs to be obtained by reference (otherwise
> compiler complains about use of deleted function unique_ptr(const
> unique_ptr&) = delete
> {
> for( auto& oField: *poFeature ) <-- this is a
> OGRFeature::FieldValue object that has no copy constructor (intended, we
> don't want user to be able to instanciate standalone FieldValue)
>
> Does that look better ?
>
> In all those above cases, the auto could also be const'ified, so the
> stricter typing would be
>
> for( const auto poLayer: poDS->GetLayers() )
> {
> for( const auto& poFeature: *poLayer )
> {
> for( const auto& oField: *poFeature )
> Should we put that instead ?
>
I believe the universal reference (&&) has no purpose in this context. It
will decay to a standard reference. So what you post is more clear.
--
Andrew Bell
andrew.bell.ia at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20180411/ce571d1a/attachment.html>
More information about the gdal-dev
mailing list