Home » Community » U++ community news and announcements » C++11 library features finished
C++11 library features finished [message #45098] |
Mon, 31 August 2015 13:38 |
|
mirek
Messages: 14112 Registered: November 2005
|
Ultimate Member |
|
|
I have finished adding C++11 features for the next release. Basically, there is support for C++11 initializers and also support for lambdas in Callbacks.
Lambdas have problem as all-catch templated constructor in std::function creates overloading issues. Previously, I was trying to solve it using LAMBDA macro, but it proved cumbersome. New approach allows direct us of lambda via operator<< (beacause we do not overload that one much for callbacks).
Demo in reference/Cpp11
#include "CtrlLib/CtrlLib.h"
using namespace Upp;
#define LAYOUTFILE <Cpp11/Cpp11.lay>
#include <CtrlCore/lay.h>
GUI_APP_MAIN
{
WithMyAppLayout<TopWindow> dlg;
CtrlLayout(dlg, "C++11 demo");
dlg.list.NoHeader().AddColumn();
Vector<int> x = { 1, 2, 12, 34, 15, 11 };
for(auto i : x)
dlg.list.Add(i);
dlg.add << [&] {
if(dlg.list.Find(~dlg.number) < 0)
dlg.list.Add(~dlg.number);
};
dlg.list.WhenSel << [&] {
dlg.number <<= dlg.list.GetKey();
};
dlg.Execute();
}
|
|
|
|
|
|
Re: C++11 library features finished [message #45463 is a reply to message #45461] |
Thu, 19 November 2015 04:41 |
Novo
Messages: 1371 Registered: December 2006
|
Ultimate Contributor |
|
|
There is another C++11 problem. Checked with MSVC2015.
One<MFile> mfile;
One<MFile> cur_mfile(new MFile);
mfile = cur_mfile; // <-- Upp::One<MFile> &Upp::One<MFile>::operator =(const Upp::One<MFile> &)': attempting to reference a deleted function
I need to detach value explicitly.
mfile = cur_mfile.Detach();
Thanks.
Regards,
Novo
|
|
|
Re: C++11 library features finished [message #45464 is a reply to message #45461] |
Thu, 19 November 2015 15:29 |
|
mirek
Messages: 14112 Registered: November 2005
|
Ultimate Member |
|
|
Mindtraveller wrote on Thu, 19 November 2015 00:59Still having rare issues with newest C++11-style code:
struct GLTextureDescriptor : Moveable<GLTextureDescriptor>
{
int w,h,wTex,hTex;
struct GLTex : Moveable<GLTex>
{
int w,h;
GLuint glId;
};
Vector<Vector<GLTex>> glTex;
};
VectorMap<String,GLTextureDescriptor> glTextureDescriptors;
//...
GLTextureDescriptor desc;
//...
glTextureDescriptors.AddPick(key, desc); // <-- compiler error, cannot cast 2nd argument to GLTextureDescriptor &&
I wasn't able to find quick & easy solution for this case.
AddPick(key, pick(desc)) should work here. Does it not?
|
|
|
|
|
Re: C++11 library features finished [message #45468 is a reply to message #45465] |
Fri, 20 November 2015 02:50 |
Novo
Messages: 1371 Registered: December 2006
|
Ultimate Contributor |
|
|
mirek wrote on Thu, 19 November 2015 09:31
Same thing... mfile = pick(cur_mfile).
Simple: You now need to be explicit, except for temporaries.
Bit more verbose, but in fact I was able to find some bugs at compile time already thanks to this..
Thanks! I missed that.
Regards,
Novo
|
|
|
|
Re: C++11 library features finished [message #46569 is a reply to message #46565] |
Wed, 01 June 2016 23:24 |
|
mirek
Messages: 14112 Registered: November 2005
|
Ultimate Member |
|
|
Uhm, perhaps you have missed the annoucement that trunk now requires c++11?
As for AtomicWrite, it is removed because it is not necessary. Just assign the damned variable...
Mirek
P.S.: You can still have 'old' U++ is you use 'classic' instead of 'trunk'.
[Updated on: Wed, 01 June 2016 23:24] Report message to a moderator
|
|
|
Re: C++11 library features finished [message #46584 is a reply to message #46569] |
Fri, 03 June 2016 19:27 |
Novo
Messages: 1371 Registered: December 2006
|
Ultimate Contributor |
|
|
code\gui\upp\trunk\uppsrc\core\map.h(178) : warning C4717: 'Upp::AMap<int,Upp::Vector<int>,Upp::Vector<Upp::Vector<int> > >::FindPutPick': recursive on all control paths, function will cause runtime stack overflow
MSVC 2015 x64.
Just to let you know.
The same problem should happen to FindAddPick and GetAddPick.
Although they are deprecated, they still are really recursive, and apps crash because of that.
I believe you wanted to implement them this way:
FindPutPick(const K& k, T&& init) { return FindPut(k, pick(init)); }
TIA.
Regards,
Novo
[Updated on: Fri, 03 June 2016 19:44] Report message to a moderator
|
|
|
|
Re: C++11 library features finished [message #46588 is a reply to message #46585] |
Sat, 04 June 2016 05:36 |
Novo
Messages: 1371 Registered: December 2006
|
Ultimate Contributor |
|
|
There is a bug in AMap<K, T, V>::FindPut(const K& k, T&& init). It should look like below.
template <class K, class T, class V>
int AMap<K, T, V>::FindPut(const K& k, T&& init)
{
unsigned hash = key.hashfn(k);
int i = Find(k, hash);
if(i < 0) {
i = key.Put(k, hash);
value.At(i) = pick(init);
}
return i;
}
The same problem can be found in other methods where you are using r-value directly (without "pick").
Below is a test case.
VectorMap<int, Vector<int> > x;
x.FindPut(1, Vector<int>());
You can just try to compile all methods taking r-value and see what happens.
EDIT: I've attached a patch.
Regards
-
Attachment: AMap.zip
(Size: 5.72KB, Downloaded 234 times)
Regards,
Novo
[Updated on: Sat, 04 June 2016 15:47] Report message to a moderator
|
|
|
|
Re: C++11 library features finished [message #46607 is a reply to message #46604] |
Fri, 10 June 2016 05:09 |
Novo
Messages: 1371 Registered: December 2006
|
Ultimate Contributor |
|
|
mirek wrote on Thu, 09 June 2016 08:05Thanks, you are completely correct.
(BTW, perhaps you have some testing code now - if yes, I can add it to nightly tests, just send it to me).
I do not have special tests for this problem. I spotted it by trying to run an old app.
I've attached another similar patch. I'm not 100% sure about each change, but it looks like I'm right.
Regards
Regards,
Novo
|
|
|
|
Goto Forum:
Current Time: Sun Nov 10 20:46:41 CET 2024
Total time taken to generate the page: 0.02910 seconds
|