From dfb033bb7a8c6de2d0113334027601ae1ada65fc Mon Sep 17 00:00:00 2001 From: Mirek Fidler Date: Fri, 8 Apr 2022 17:02:39 +0200 Subject: [PATCH] uppsrc: C++20 compatibility --- uppsrc/Core/CoWork.h | 8 ++++++++ uppsrc/Core/Color.h | 1 + uppsrc/Core/Gtypes.h | 6 +++--- uppsrc/Core/InVector.h | 6 ++++++ uppsrc/Core/Index.h | 2 ++ uppsrc/Core/Mt.cpp | 3 ++- uppsrc/Core/Range.h | 8 ++++++++ uppsrc/Core/ValueUtil.h | 3 ++- uppsrc/Core/Vcont.h | 4 ++++ uppsrc/Core/config.h | 26 +++++++++++++++++++++++--- uppsrc/CtrlCore/CtrlCore.h | 6 +++--- uppsrc/CtrlCore/CtrlPos.cpp | 2 +- uppsrc/CtrlCore/MKeys.h | 6 +++--- uppsrc/Painter/BufferPainter.h | 4 ++-- uppsrc/Painter/Render.cpp | 2 +- 15 files changed, 69 insertions(+), 18 deletions(-) diff --git a/uppsrc/Core/CoWork.h b/uppsrc/Core/CoWork.h index 1eb7b4404..1cd45b34d 100644 --- a/uppsrc/Core/CoWork.h +++ b/uppsrc/Core/CoWork.h @@ -226,18 +226,26 @@ public: template< class Function, class... Args> AsyncWork< +#ifdef CPP_20 + std::invoke_result_t +#else typename std::result_of< typename std::decay::type (typename std::decay::type...) >::type +#endif > Async(Function&& f, Args&&... args) { AsyncWork< +#ifdef CPP_20 + std::invoke_result_t +#else typename std::result_of< typename std::decay::type (typename std::decay::type...) >::type +#endif > h; h.Do(f, args...); return pick(h); diff --git a/uppsrc/Core/Color.h b/uppsrc/Core/Color.h index dea57bd41..5b9f0e515 100644 --- a/uppsrc/Core/Color.h +++ b/uppsrc/Core/Color.h @@ -55,6 +55,7 @@ public: bool IsNullInstance() const { return color == 0xffffffff; } hash_t GetHashValue() const { return color; } bool operator==(Color c) const { return color == c.color; } + bool operator==(const RGBA& c) const { return c == operator RGBA(); } bool operator!=(Color c) const { return color != c.color; } void Serialize(Stream& s) { s % color; } diff --git a/uppsrc/Core/Gtypes.h b/uppsrc/Core/Gtypes.h index e7bf0ceac..d08678c3f 100644 --- a/uppsrc/Core/Gtypes.h +++ b/uppsrc/Core/Gtypes.h @@ -64,7 +64,7 @@ struct Size_ : Moveable< Size_ > { Size_(T cx, T cy) : cx(cx), cy(cy) {} Size_(const Size_& sz) : cx((T)sz.cx), cy((T)sz.cy) {} - Size_(const Size_& sz) : cx((T)sz.cx), cy((T)sz.cy) {} + Size_(const Size_& sz) : cx((T)sz.cx), cy((T)sz.cy) {} Size_(const Size_& sz) : cx((T)sz.cx), cy((T)sz.cy) {} Size_(const Size_& sz) : cx((T)sz.cx), cy((T)sz.cy) {} @@ -175,7 +175,7 @@ struct Point_ : Moveable< Point_ > { Point_(T x, T y) : x(x), y(y) {} Point_(const Point_& pt) : x((T)pt.x), y((T)pt.y) {} - Point_(const Point_& pt) : x((T)pt.x), y((T)pt.y) {} + Point_(const Point_& pt) : x((T)pt.x), y((T)pt.y) {} Point_(const Point_& pt) : x((T)pt.x), y((T)pt.y) {} Point_(const Point_& pt) : x((T)pt.x), y((T)pt.y) {} @@ -368,7 +368,7 @@ struct Rect_ : Moveable< Rect_ > { Rect_(Sz sz) { Set(0, 0, sz.cx, sz.cy); } Rect_(const Rect_& r) { Set((T)r.left, (T)r.top, (T)r.right, (T)r.bottom); } - Rect_(const Rect_& r) { Set((T)r.left, (T)r.top, (T)r.right, (T)r.bottom); } + Rect_(const Rect_& r) { Set((T)r.left, (T)r.top, (T)r.right, (T)r.bottom); } Rect_(const Rect_& r) { Set((T)r.left, (T)r.top, (T)r.right, (T)r.bottom); } Rect_(const Rect_& r) { Set((T)r.left, (T)r.top, (T)r.right, (T)r.bottom); } diff --git a/uppsrc/Core/InVector.h b/uppsrc/Core/InVector.h index eb5da6ade..bffa06db2 100644 --- a/uppsrc/Core/InVector.h +++ b/uppsrc/Core/InVector.h @@ -154,7 +154,9 @@ public: String ToString() const; hash_t GetHashValue() const { return HashBySerialize(*this); } template bool operator==(const B& b) const { return IsEqualRange(*this, b); } +#ifndef CPP_20 template bool operator!=(const B& b) const { return !operator==(b); } +#endif template int Compare(const B& b) const { return CompareRanges(*this, b); } template bool operator<=(const B& x) const { return Compare(x) <= 0; } template bool operator>=(const B& x) const { return Compare(x) >= 0; } @@ -382,7 +384,9 @@ public: String ToString() const; hash_t GetHashValue() const { return HashBySerialize(*this); } template bool operator==(const B& b) const { return IsEqualRange(*this, b); } +#ifndef CPP_20 template bool operator!=(const B& b) const { return !operator==(b); } +#endif template int Compare(const B& b) const { return CompareRanges(*this, b); } template bool operator<=(const B& x) const { return Compare(x) <= 0; } template bool operator>=(const B& x) const { return Compare(x) >= 0; } @@ -528,7 +532,9 @@ public: hash_t GetHashValue() const { return HashBySerialize(*this); } template bool operator==(const B& b) const { return IsEqualRange(*this, b); } +#ifndef CPP_20 template bool operator!=(const B& b) const { return !operator==(b); } +#endif template int Compare(const B& b) const { return CompareRanges(*this, b); } template bool operator<=(const B& x) const { return Compare(x) <= 0; } template bool operator>=(const B& x) const { return Compare(x) >= 0; } diff --git a/uppsrc/Core/Index.h b/uppsrc/Core/Index.h index ff1cb226d..9e8c3dbed 100644 --- a/uppsrc/Core/Index.h +++ b/uppsrc/Core/Index.h @@ -143,7 +143,9 @@ public: void Jsonize(JsonIO& jio); String ToString() const; template bool operator==(const B& b) const { return IsEqualRange(*this, b); } +#ifndef CPP_20 template bool operator!=(const B& b) const { return !operator==(b); } +#endif template int Compare(const B& b) const { return CompareRanges(*this, b); } template bool operator<=(const B& x) const { return Compare(x) <= 0; } template bool operator>=(const B& x) const { return Compare(x) >= 0; } diff --git a/uppsrc/Core/Mt.cpp b/uppsrc/Core/Mt.cpp index d94e88056..e7b77e47c 100644 --- a/uppsrc/Core/Mt.cpp +++ b/uppsrc/Core/Mt.cpp @@ -734,7 +734,8 @@ void SpinLock::Wait() #ifdef CPU_X86 _mm_pause(); #endif - if(n++ > 500) + n = n + 1; + if(n > 500) Sleep(0); } } diff --git a/uppsrc/Core/Range.h b/uppsrc/Core/Range.h index 02ff21c5b..2ac6fed01 100644 --- a/uppsrc/Core/Range.h +++ b/uppsrc/Core/Range.h @@ -28,7 +28,9 @@ public: String ToString() const { return AsStringArray(*this); } template bool operator==(const B& b) const { return IsEqualRange(*this, b); } +#ifndef CPP_20 template bool operator!=(const B& b) const { return !operator==(b); } +#endif template int Compare(const B& b) const { return CompareRanges(*this, b); } template bool operator<=(const B& x) const { return Compare(x) <= 0; } template bool operator>=(const B& x) const { return Compare(x) >= 0; } @@ -78,7 +80,9 @@ struct ConstRangeClass { String ToString() const { return AsStringArray(*this); } template bool operator==(const B& b) const { return IsEqualRange(*this, b); } +#ifndef CPP_20 template bool operator!=(const B& b) const { return !operator==(b); } +#endif template int Compare(const B& b) const { return CompareRanges(*this, b); } template bool operator<=(const B& x) const { return Compare(x) <= 0; } template bool operator>=(const B& x) const { return Compare(x) >= 0; } @@ -126,7 +130,9 @@ struct ReverseRangeClass { String ToString() const { return AsStringArray(*this); } template bool operator==(const B& b) const { return IsEqualRange(*this, b); } +#ifndef CPP_20 template bool operator!=(const B& b) const { return !operator==(b); } +#endif template int Compare(const B& b) const { return CompareRanges(*this, b); } template bool operator<=(const B& x) const { return Compare(x) <= 0; } template bool operator>=(const B& x) const { return Compare(x) >= 0; } @@ -168,7 +174,9 @@ struct ViewRangeClass { String ToString() const { return AsStringArray(*this); } template bool operator==(const B& b) const { return IsEqualRange(*this, b); } +#ifndef CPP_20 template bool operator!=(const B& b) const { return !operator==(b); } +#endif template int Compare(const B& b) const { return CompareRanges(*this, b); } template bool operator<=(const B& x) const { return Compare(x) <= 0; } template bool operator>=(const B& x) const { return Compare(x) >= 0; } diff --git a/uppsrc/Core/ValueUtil.h b/uppsrc/Core/ValueUtil.h index abb3ecb0e..c8299c358 100644 --- a/uppsrc/Core/ValueUtil.h +++ b/uppsrc/Core/ValueUtil.h @@ -83,8 +83,9 @@ public: operator const String&() const { return ToString(); } const String& operator~() const { return ToString(); } bool operator==(const Id& b) const { return id == b.id; } + bool operator==(const String& b) const { return id == b; } + bool operator==(const char *b) const { return id == b; } bool operator!=(const Id& b) const { return id != b.id; } - operator bool() const { return id.GetCount(); } Id() {} diff --git a/uppsrc/Core/Vcont.h b/uppsrc/Core/Vcont.h index e101d3ac5..04856fd42 100644 --- a/uppsrc/Core/Vcont.h +++ b/uppsrc/Core/Vcont.h @@ -267,7 +267,9 @@ public: String ToString() const; hash_t GetHashValue() const { return HashBySerialize(*this); } template bool operator==(const B& b) const { return IsEqualRange(*this, b); } +#ifndef CPP_20 template bool operator!=(const B& b) const { return !operator==(b); } +#endif template int Compare(const B& b) const { return CompareRanges(*this, b); } template bool operator<=(const B& x) const { return Compare(x) <= 0; } template bool operator>=(const B& x) const { return Compare(x) >= 0; } @@ -423,7 +425,9 @@ public: hash_t GetHashValue() const { return HashBySerialize(*this); } template bool operator==(const B& b) const { return IsEqualRange(*this, b); } +#ifndef CPP_20 template bool operator!=(const B& b) const { return !operator==(b); } +#endif template int Compare(const B& b) const { return CompareRanges(*this, b); } template bool operator<=(const B& x) const { return Compare(x) <= 0; } template bool operator>=(const B& x) const { return Compare(x) >= 0; } diff --git a/uppsrc/Core/config.h b/uppsrc/Core/config.h index 87123f2ed..706f8e31f 100644 --- a/uppsrc/Core/config.h +++ b/uppsrc/Core/config.h @@ -177,12 +177,32 @@ #define STD_NEWDELETE #endif -#if __cplusplus >= 201100 +#if __cplusplus >= 201103 #define CPP_11 #endif -#if _MSC_VER >= 1900 // MSC from VS2015 is good enough C++11 compiler... -#define CPP_11 +#if __cplusplus >= 201402 +#define CPP_14 +#endif + +#if __cplusplus >= 201703 +#define CPP_17 +#endif + +#if __cplusplus >= 202002 +#define CPP_20 +#endif + +#if _MSVC_LANG >= 201402 +#define CPP_14 +#endif + +#if _MSVC_LANG >= 201703 +#define CPP_17 +#endif + +#if _MSVC_LANG >= 202002 +#define CPP_20 #endif #define WCHAR32 1 // this version of U++ has 32 bit wchar diff --git a/uppsrc/CtrlCore/CtrlCore.h b/uppsrc/CtrlCore/CtrlCore.h index f73cc663d..7927a513b 100644 --- a/uppsrc/CtrlCore/CtrlCore.h +++ b/uppsrc/CtrlCore/CtrlCore.h @@ -82,7 +82,7 @@ typedef ImageDraw SystemImageDraw; void SetSurface(Draw& w, const Rect& dest, const RGBA *pixels, Size srcsz, Point poff); void SetSurface(Draw& w, int x, int y, int cx, int cy, const RGBA *pixels); -enum { +const dword K_DELTA = 0x200000, K_CHAR_LIM = 0x200000, // lower that this, key in Key is Unicode codepoint @@ -109,8 +109,8 @@ enum { IK_DBL_CLICK = 0x40000001, // this is just to get the info that the entry is equal to dbl-click to the menu K_MOUSE_FORWARD = 0x80000001, - K_MOUSE_BACKWARD = 0x80000002, -}; + K_MOUSE_BACKWARD = 0x80000002 +; #include "MKeys.h" diff --git a/uppsrc/CtrlCore/CtrlPos.cpp b/uppsrc/CtrlCore/CtrlPos.cpp index dba72de50..5a83c7b54 100644 --- a/uppsrc/CtrlCore/CtrlPos.cpp +++ b/uppsrc/CtrlCore/CtrlPos.cpp @@ -149,7 +149,7 @@ void Ctrl::SyncLayout(int force) for(int i = 0; i < frame.GetCount(); i++) { Frame& f = frame[i]; f.frame->FrameLayout(view); - if(view != f.view) { + if(view != Rect(f.view)) { f.view = view; refresh = true; } diff --git a/uppsrc/CtrlCore/MKeys.h b/uppsrc/CtrlCore/MKeys.h index 001275fb9..038a5806a 100644 --- a/uppsrc/CtrlCore/MKeys.h +++ b/uppsrc/CtrlCore/MKeys.h @@ -1,4 +1,4 @@ -enum CtrlCoreKeys { +const dword #ifdef GUIPLATFORM_KEYCODES_INCLUDE #include GUIPLATFORM_KEYCODES_INCLUDE #else @@ -357,5 +357,5 @@ enum CtrlCoreKeys { K_ALT_8 = K_ALT|K_8, K_ALT_9 = K_ALT|K_9, - K_CTRL_BREAK = K_CTRL|K_BREAK, -}; + K_CTRL_BREAK = K_CTRL|K_BREAK +; diff --git a/uppsrc/Painter/BufferPainter.h b/uppsrc/Painter/BufferPainter.h index b73b5eac3..c1fc1d72b 100644 --- a/uppsrc/Painter/BufferPainter.h +++ b/uppsrc/Painter/BufferPainter.h @@ -297,8 +297,8 @@ private: void FinishFillJob() { fill_job.Finish(); } void SyncCo(); - - enum { FILL = -1, CLIP = -2, ONPATH = -3 }; + + static const int FILL = -1, CLIP = -2, ONPATH = -3; public: ImageBuffer& GetBuffer() { return *ip; } diff --git a/uppsrc/Painter/Render.cpp b/uppsrc/Painter/Render.cpp index 5e279d8ac..841a1e43a 100644 --- a/uppsrc/Painter/Render.cpp +++ b/uppsrc/Painter/Render.cpp @@ -42,7 +42,7 @@ BufferPainter::PathJob::PathJob(Rasterizer& rasterizer, double width, const Path tolerance = 0.3 / attr.mtx.GetScale(); } - if(width == ONPATH) { + if(width == BufferPainter::ONPATH) { g = &onpathtarget; regular = false; }