On Fri, 15 Dec 2017, Even Rouault wrote:
Kurt,
It doesn't look like constexpr is available in VS2013 (at least not in all
sub-versions of it):
https://stackoverflow.com/questions/20264644/constexpr-not-compiling-in-vc2013
Personnally, I don't see it as a super needed feature that would justify
dropping VS2013
support. Especially in the below use cases where it doesn't bring anything more
than const,
except more characters to type/read. I'd bet any sane compiler in -O2 will
compile the source
to the same machine code in all those cases
As a C programmer, writing gdal device drivers is teaching me much about
C++, but I'm finding it difficult to understand why I should need to care
whether a const is a constexpr.
Except in the rare case where I might want a value that cannot be initialised
at compile time, but my code must not change once it has been initialised,
I don't see the need to distinguish between the two and wish that a const
was a constexpr unless otherwise declared.
I worry that Kurt's improvements are turning C++ into a foreign language
for me.
On vendredi 15 décembre 2017 07:04:23 CET you wrote:
Author: goatbar
Date: 2017-12-15 07:04:23 -0800 (Fri, 15 Dec 2017)
New Revision: 41044
Modified:
trunk/gdal/port/cpl_conv.cpp
Log:
const -> constexpr for things known at compile time in cpl_conv.cpp
Modified: trunk/gdal/port/cpl_conv.cpp
===================================================================
--- trunk/gdal/port/cpl_conv.cpp 2017-12-15 14:37:43 UTC (rev 41043)
+++ trunk/gdal/port/cpl_conv.cpp 2017-12-15 15:04:23 UTC (rev 41044)
@@ -340,8 +340,8 @@
/************************************************************************/
// ASCII characters.
-static const char knLF = 10;
-static const char knCR = 13;
+constexpr char knLF = 10;
+constexpr char knCR = 13;
/**
* Reads in at most one less than nBufferSize characters from the fp
@@ -666,7 +666,7 @@
/* the line. */
/* -------------------------------------------------------------------- */
char *pszRLBuffer = nullptr;
- const size_t nChunkSize = 40;
+ constexpr size_t nChunkSize = 40;
char szChunk[nChunkSize] = {};
size_t nChunkBytesRead = 0;
int nBufLength = 0;
@@ -1984,8 +1984,8 @@
/* CPLDMSToDec() */
/************************************************************************/
-static const char *sym = "NnEeSsWw";
-static const double vm[] = { 1.0, 0.0166666666667, 0.00027777778 };
+constexpr char sym[] = "NnEeSsWw";
+constexpr double vm[] = { 1.0, 0.0166666666667, 0.00027777778 };
/** CPLDMSToDec */
double CPLDMSToDec( const char *is )
@@ -2605,7 +2605,7 @@
/* -------------------------------------------------------------------- */
/* Prepare buffer. */
/* -------------------------------------------------------------------- */
- const size_t nBufferSize = 1024 * 1024;
+ constexpr size_t nBufferSize = 1024 * 1024;
GByte *pabyBuffer = static_cast<GByte
*>(VSI_MALLOC_VERBOSE(nBufferSize)); if( pabyBuffer == nullptr )
{
_______________________________________________
gdal-commits mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/gdal-commits
--
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/gdal-dev