uppsrc: C++20 compatibility

This commit is contained in:
Mirek Fidler 2022-04-08 17:02:39 +02:00
parent 9d56de714c
commit dfb033bb7a
15 changed files with 69 additions and 18 deletions

View file

@ -226,18 +226,26 @@ public:
template< class Function, class... Args>
AsyncWork<
#ifdef CPP_20
std::invoke_result_t<Function, Args...>
#else
typename std::result_of<
typename std::decay<Function>::type
(typename std::decay<Args>::type...)
>::type
#endif
>
Async(Function&& f, Args&&... args)
{
AsyncWork<
#ifdef CPP_20
std::invoke_result_t<Function, Args...>
#else
typename std::result_of<
typename std::decay<Function>::type
(typename std::decay<Args>::type...)
>::type
#endif
> h;
h.Do(f, args...);
return pick(h);

View file

@ -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; }

View file

@ -64,7 +64,7 @@ struct Size_ : Moveable< Size_<T> > {
Size_(T cx, T cy) : cx(cx), cy(cy) {}
Size_(const Size_<int>& sz) : cx((T)sz.cx), cy((T)sz.cy) {}
Size_(const Size_<short>& sz) : cx((T)sz.cx), cy((T)sz.cy) {}
Size_(const Size_<int16>& sz) : cx((T)sz.cx), cy((T)sz.cy) {}
Size_(const Size_<double>& sz) : cx((T)sz.cx), cy((T)sz.cy) {}
Size_(const Size_<int64>& sz) : cx((T)sz.cx), cy((T)sz.cy) {}
@ -175,7 +175,7 @@ struct Point_ : Moveable< Point_<T> > {
Point_(T x, T y) : x(x), y(y) {}
Point_(const Point_<int>& pt) : x((T)pt.x), y((T)pt.y) {}
Point_(const Point_<short>& pt) : x((T)pt.x), y((T)pt.y) {}
Point_(const Point_<int16>& pt) : x((T)pt.x), y((T)pt.y) {}
Point_(const Point_<double>& pt) : x((T)pt.x), y((T)pt.y) {}
Point_(const Point_<int64>& pt) : x((T)pt.x), y((T)pt.y) {}
@ -368,7 +368,7 @@ struct Rect_ : Moveable< Rect_<T> > {
Rect_(Sz sz) { Set(0, 0, sz.cx, sz.cy); }
Rect_(const Rect_<int>& r) { Set((T)r.left, (T)r.top, (T)r.right, (T)r.bottom); }
Rect_(const Rect_<short>& r) { Set((T)r.left, (T)r.top, (T)r.right, (T)r.bottom); }
Rect_(const Rect_<int16>& r) { Set((T)r.left, (T)r.top, (T)r.right, (T)r.bottom); }
Rect_(const Rect_<double>& r) { Set((T)r.left, (T)r.top, (T)r.right, (T)r.bottom); }
Rect_(const Rect_<int64>& r) { Set((T)r.left, (T)r.top, (T)r.right, (T)r.bottom); }

View file

@ -154,7 +154,9 @@ public:
String ToString() const;
hash_t GetHashValue() const { return HashBySerialize(*this); }
template <class B> bool operator==(const B& b) const { return IsEqualRange(*this, b); }
#ifndef CPP_20
template <class B> bool operator!=(const B& b) const { return !operator==(b); }
#endif
template <class B> int Compare(const B& b) const { return CompareRanges(*this, b); }
template <class B> bool operator<=(const B& x) const { return Compare(x) <= 0; }
template <class B> 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 <class B> bool operator==(const B& b) const { return IsEqualRange(*this, b); }
#ifndef CPP_20
template <class B> bool operator!=(const B& b) const { return !operator==(b); }
#endif
template <class B> int Compare(const B& b) const { return CompareRanges(*this, b); }
template <class B> bool operator<=(const B& x) const { return Compare(x) <= 0; }
template <class B> bool operator>=(const B& x) const { return Compare(x) >= 0; }
@ -528,7 +532,9 @@ public:
hash_t GetHashValue() const { return HashBySerialize(*this); }
template <class B> bool operator==(const B& b) const { return IsEqualRange(*this, b); }
#ifndef CPP_20
template <class B> bool operator!=(const B& b) const { return !operator==(b); }
#endif
template <class B> int Compare(const B& b) const { return CompareRanges(*this, b); }
template <class B> bool operator<=(const B& x) const { return Compare(x) <= 0; }
template <class B> bool operator>=(const B& x) const { return Compare(x) >= 0; }

View file

@ -143,7 +143,9 @@ public:
void Jsonize(JsonIO& jio);
String ToString() const;
template <class B> bool operator==(const B& b) const { return IsEqualRange(*this, b); }
#ifndef CPP_20
template <class B> bool operator!=(const B& b) const { return !operator==(b); }
#endif
template <class B> int Compare(const B& b) const { return CompareRanges(*this, b); }
template <class B> bool operator<=(const B& x) const { return Compare(x) <= 0; }
template <class B> bool operator>=(const B& x) const { return Compare(x) >= 0; }

View file

@ -734,7 +734,8 @@ void SpinLock::Wait()
#ifdef CPU_X86
_mm_pause();
#endif
if(n++ > 500)
n = n + 1;
if(n > 500)
Sleep(0);
}
}

View file

@ -28,7 +28,9 @@ public:
String ToString() const { return AsStringArray(*this); }
template <class B> bool operator==(const B& b) const { return IsEqualRange(*this, b); }
#ifndef CPP_20
template <class B> bool operator!=(const B& b) const { return !operator==(b); }
#endif
template <class B> int Compare(const B& b) const { return CompareRanges(*this, b); }
template <class B> bool operator<=(const B& x) const { return Compare(x) <= 0; }
template <class B> bool operator>=(const B& x) const { return Compare(x) >= 0; }
@ -78,7 +80,9 @@ struct ConstRangeClass {
String ToString() const { return AsStringArray(*this); }
template <class B> bool operator==(const B& b) const { return IsEqualRange(*this, b); }
#ifndef CPP_20
template <class B> bool operator!=(const B& b) const { return !operator==(b); }
#endif
template <class B> int Compare(const B& b) const { return CompareRanges(*this, b); }
template <class B> bool operator<=(const B& x) const { return Compare(x) <= 0; }
template <class B> bool operator>=(const B& x) const { return Compare(x) >= 0; }
@ -126,7 +130,9 @@ struct ReverseRangeClass {
String ToString() const { return AsStringArray(*this); }
template <class B> bool operator==(const B& b) const { return IsEqualRange(*this, b); }
#ifndef CPP_20
template <class B> bool operator!=(const B& b) const { return !operator==(b); }
#endif
template <class B> int Compare(const B& b) const { return CompareRanges(*this, b); }
template <class B> bool operator<=(const B& x) const { return Compare(x) <= 0; }
template <class B> bool operator>=(const B& x) const { return Compare(x) >= 0; }
@ -168,7 +174,9 @@ struct ViewRangeClass {
String ToString() const { return AsStringArray(*this); }
template <class B> bool operator==(const B& b) const { return IsEqualRange(*this, b); }
#ifndef CPP_20
template <class B> bool operator!=(const B& b) const { return !operator==(b); }
#endif
template <class B> int Compare(const B& b) const { return CompareRanges(*this, b); }
template <class B> bool operator<=(const B& x) const { return Compare(x) <= 0; }
template <class B> bool operator>=(const B& x) const { return Compare(x) >= 0; }

View file

@ -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() {}

View file

@ -267,7 +267,9 @@ public:
String ToString() const;
hash_t GetHashValue() const { return HashBySerialize(*this); }
template <class B> bool operator==(const B& b) const { return IsEqualRange(*this, b); }
#ifndef CPP_20
template <class B> bool operator!=(const B& b) const { return !operator==(b); }
#endif
template <class B> int Compare(const B& b) const { return CompareRanges(*this, b); }
template <class B> bool operator<=(const B& x) const { return Compare(x) <= 0; }
template <class B> bool operator>=(const B& x) const { return Compare(x) >= 0; }
@ -423,7 +425,9 @@ public:
hash_t GetHashValue() const { return HashBySerialize(*this); }
template <class B> bool operator==(const B& b) const { return IsEqualRange(*this, b); }
#ifndef CPP_20
template <class B> bool operator!=(const B& b) const { return !operator==(b); }
#endif
template <class B> int Compare(const B& b) const { return CompareRanges(*this, b); }
template <class B> bool operator<=(const B& x) const { return Compare(x) <= 0; }
template <class B> bool operator>=(const B& x) const { return Compare(x) >= 0; }

View file

@ -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

View file

@ -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"

View file

@ -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;
}

View file

@ -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
;

View file

@ -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; }

View file

@ -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;
}