Home » U++ Library support » U++ Core » Deprecating THISBACK (Post 2020.2 release)
Deprecating THISBACK [message #55122] |
Mon, 12 October 2020 22:31 |
|
Klugier
Messages: 1079 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello,
I had the discussion with Mirek about this article https://evileg.com/en/post/629/ he found that the user uses deprecated THISBACK construction. Well we deprecated it in the documentation in favor or lambdas or newer c++ constructions such as Function, Gate etc.
In c++14 which we targets on all platforms the solution is easy. We can deprecate it on compilation level, which means something. Just mark THISBACK with deprecated atribute like this:
[[deprecated("THISBACK is deprecated use lambda instead.")]]
const int thisbackd = 0;
#define THISBACK(x) callback(this + thisbackd, &CLASSNAME::x)
#define THISBACK1(x, arg) callback1(this + thisbackd, &CLASSNAME::x, arg)
#define THISBACK2(m, a, b) callback2(this + thisbackd, &CLASSNAME::m, a, b)
#define THISBACK3(m, a, b, c) callback3(this + thisbackd, &CLASSNAME::m, a, b, c)
#define THISBACK4(m, a, b, c, d) callback4(this + thisbackd, &CLASSNAME::m, a, b, c, d)
#define THISBACK5(m, a, b, c, d, e) callback5(this + thisbackd, &CLASSNAME::m, a, b, c, d,e)
Then in all places when THISBACK is used the warning pop up "/home/klugier/upp/uppsrc/CtrlLib/FileSel.h (239): warning: 'thisbackd' is deprecated: THISBACK is deprecated use lambda instead. [-Wdeprecated-declarations]".
If you are not aware how you should replace thisback. Example below:
void MyWidnow::ErrorMenu(Bar& bar)
// bar.Add("Copy all", THISBACK1(CopyError, true));
bar.Add("Copy all", [=] { CopyError(true); });
// In the header file no need for "typedef MyWindow CLASSNAME" declaration...
I think we have multiple places when [[deprecated]] macro can be used. If you search for "deprecated" in uppsrc then there is around 52 entries... Definitely not the topic for 2020.2, but for 2021.1...
Klugier
U++ - one framework to rule them all.
[Updated on: Tue, 13 October 2020 11:29] Report message to a moderator
|
|
|
Re: Deprecating THISBACK [message #55125 is a reply to message #55122] |
Mon, 12 October 2020 23:25 |
|
mirek
Messages: 14016 Registered: November 2005
|
Ultimate Member |
|
|
Klugier wrote on Mon, 12 October 2020 22:31Hello,
I had the discussion with Mirek about this article https://evileg.com/en/post/629/ he found that the user uses deprecated THISBACK construction. Well we deprecated it in the documentation in favor or lambdas or newer c++ constructions such as Function, Gate etc.
In c++14 which we targets on all platforms the solution is easy. We can deprecate it on compilation level, which means something. Just mark THISBACK with deprecated atribute like this:
[[deprecated("THISBACK is deprecated use lambda instead.")]]
const int thisbackd = 0;
#define THISBACK(x) callback(this + thisbackd, &CLASSNAME::x)
#define THISBACK1(x, arg) callback1(this + thisbackd, &CLASSNAME::x, arg)
#define THISBACK2(m, a, b) callback2(this + thisbackd, &CLASSNAME::m, a, b)
#define THISBACK3(m, a, b, c) callback3(this + thisbackd, &CLASSNAME::m, a, b, c)
#define THISBACK4(m, a, b, c, d) callback4(this + thisbackd, &CLASSNAME::m, a, b, c, d)
#define THISBACK5(m, a, b, c, d, e) callback5(this + thisbackd, &CLASSNAME::m, a, b, c, d,e)
Then in all places when THISBACK is used the warning pop up "/home/klugier/upp/uppsrc/CtrlLib/FileSel.h (239): warning: 'thisbackd' is deprecated: THISBACK is deprecated use lambda instead. [-Wdeprecated-declarations]".
I think we have multiple places when [[deprecated]] macro can be used. If you search for "deprecated" in uppsrc then there is around 52 entries... Definitely not the topic for 2020.2, but for 2021.1...
Klugier
I generally hate this. This would mean that I would have to fix a tons of code to avoid that warning for no good reason. Like a week of work...
Mirek
|
|
|
|
|
Re: Deprecating THISBACK [message #55158 is a reply to message #55129] |
Thu, 15 October 2020 00:10 |
|
Klugier
Messages: 1079 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello,
Backing to this problem. I see that several templates (.upt) have CLASSNAME declaration. From my perspective the good idea would be to remove that declaration. After that all new code shouldn't have dependency to THISBACK:
CtrlLib/Complex.upt:
...
class <:classname:> : public <:lay > 1 ? "With" + classname + "Layout<TopWindow>" : "TopWindow":> {
public:
typedef <:classname:> CLASSNAME;
<:classname:>();
};
...
Could be:
...
class <:classname:> : public <:lay > 1 ? "With" + classname + "Layout<TopWindow>" : "TopWindow":> {
public:
<:classname:>();
};
...
Skylark and Tutrle templates are also affected...
Klugier
U++ - one framework to rule them all.
[Updated on: Thu, 15 October 2020 00:11] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Deprecating THISBACK [message #57088 is a reply to message #57086] |
Sun, 23 May 2021 14:46 |
|
Klugier
Messages: 1079 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello MeerMusik,
Yes, you should use lambdas instead of THISBACK for creating menus. Last year, I updated our GUI tutorial to illustrate these changes. Please, check all topics related to menus:
- 7. Menu (Also 8, 9 & 10 are valuable)
- 11. Toolbar
Klugier
U++ - one framework to rule them all.
[Updated on: Sun, 23 May 2021 14:47] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Thu Sep 12 02:24:25 CEST 2024
Total time taken to generate the page: 0.02926 seconds
|