From 66b1b09472d171a9ee570edfbf4d5608087bbb03 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 8 Nov 2024 18:25:02 +0100 Subject: [PATCH] With C++23 and __STDCPP_FLOAT16_T__, make GFloat16 an alias of std::float16_t --- port/cpl_float.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/port/cpl_float.h b/port/cpl_float.h index fbef9c2065c6..208e65213027 100644 --- a/port/cpl_float.h +++ b/port/cpl_float.h @@ -56,6 +56,9 @@ #include #include #include +#if defined(__STDCPP_FLOAT16_T__) +#include +#endif #endif CPL_C_START @@ -70,6 +73,8 @@ GUInt16 CPL_DLL CPLFloatToHalf(GUInt32 iFloat32, bool &bHasWarned); GUInt16 CPL_DLL CPLConvertFloatToHalf(float fFloat32); float CPL_DLL CPLConvertHalfToFloat(GUInt16 nHalf); +#if !defined(__STDCPP_FLOAT16_T__) + namespace cpl { @@ -538,7 +543,13 @@ struct CPLFloat16 //! @endcond } // namespace cpl +#endif // !defined(__STDCPP_FLOAT16_T__) + +#ifdef __STDCPP_FLOAT16_T__ +using GFloat16 = std::float16_t; +#else using GFloat16 = cpl::CPLFloat16; +#endif // Define some GDAL wrappers. Their C equivalents are defined in `cpl_port.h`. // (These wrappers are not necessary any mroe in C++, one can always @@ -567,6 +578,7 @@ template constexpr int CPLIsFinite(T x) return isfinite(x); } +#if !defined(__STDCPP_FLOAT16_T__) namespace std { @@ -627,6 +639,7 @@ template <> struct numeric_limits //! @endcond } // namespace std +#endif // !defined(__STDCPP_FLOAT16_T__) #endif