[gdal-dev] Initializing vectors

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[gdal-dev] Initializing vectors

Kurt Schwehr-2
Hi Even,

Trying to get caught up going through patches.  A comment for this one:


You can size and initialize a vector in the constructor.  With this code:

    std::vector<bool> abRequireNewOverview;
    abRequireNewOverview.resize(nOverviews);
    for( int i = 0; i < nOverviews && eErr == CE_None; ++i )
    {
        abRequireNewOverview[i] = true;

The vector can be setup all at one go...

    std::vector<bool> abRequireNewOverview(nOverviews, true);

See http://en.cppreference.com/w/cpp/container/vector/vector  The alloc will be set to the default.

     vector( size_type count, 
                 const T& value,
                 const Allocator& alloc = Allocator());

As for vector<bool>'s sadness, I am not really liking std::bitset for here, so as long as we are careful, we can use it as long as we are careful not hit its sharp edges.

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Initializing vectors

Even Rouault-2

On mardi 15 mai 2018 14:09:45 CEST Kurt Schwehr wrote:

> Hi Even,

>

> Trying to get caught up going through patches. A comment for this one:

>

> https://github.com/OSGeo/gdal/blob/f7c27a807b27cf74cf4666ffe3df4d64cc3f47b3/

> gdal/frmts/gtiff/geotiff.cpp

>

> You can size and initialize a vector in the constructor. With this code:

>

> std::vector<bool> abRequireNewOverview;

> abRequireNewOverview.resize(nOverviews);

> for( int i = 0; i < nOverviews && eErr == CE_None; ++i )

> {

> abRequireNewOverview[i] = true;

>

> The vector can be setup all at one go...

>

> std::vector<bool> abRequireNewOverview(nOverviews, true);

 

Kurt,

 

Yeah, I know this kind of initialization exists. My issue is that I never remember if this is count, value or value, count and when this is a vector<int> (and presumably vector<bool>), the compiler cannot yell at you if you got it wrong... I miss named parameters there...

 

That said I've fixed the above instance and similar ones as you suggest.

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev