Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
mirek is currently offline  mirek
Messages: 13428
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 #45100 is a reply to message #45098] Mon, 31 August 2015 15:16 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Very cool, thank you!
It looks like time to get used to new coding style. Finally we have inlined (lambda) callbacks without declaring new member functions.
Re: C++11 library features finished [message #45448 is a reply to message #45098] Sun, 15 November 2015 17:16 Go to previous messageGo to next message
slashupp is currently offline  slashupp
Messages: 211
Registered: July 2009
Experienced Member

Am using this feature all-over the place now
brilliant time & effort saver

thx
Re: C++11 library features finished [message #45461 is a reply to message #45448] Thu, 19 November 2015 00:59 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Still 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.
Re: C++11 library features finished [message #45463 is a reply to message #45461] Thu, 19 November 2015 04:41 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1261
Registered: December 2006
Senior 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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13428
Registered: November 2005
Ultimate Member
Mindtraveller wrote on Thu, 19 November 2015 00:59
Still 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 #45465 is a reply to message #45463] Thu, 19 November 2015 15:31 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13428
Registered: November 2005
Ultimate Member
Novo wrote on Thu, 19 November 2015 04:41
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.


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..
Re: C++11 library features finished [message #45466 is a reply to message #45464] Thu, 19 November 2015 18:05 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Mirek, you are absolutely right. Somehow I forgot to use pick/AddPick combination. C++11-style coding rules seem more strict but it should help avoid bugs. Thanks!

[Updated on: Thu, 19 November 2015 18:06]

Report message to a moderator

Re: C++11 library features finished [message #45468 is a reply to message #45465] Fri, 20 November 2015 02:50 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1261
Registered: December 2006
Senior 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 #46565 is a reply to message #45098] Wed, 01 June 2016 03:22 Go to previous messageGo to next message
Alboni is currently offline  Alboni
Messages: 204
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
Something weird going on. I had an accident with my .upp folder and deleted it. Now that hasn't been a disaster before; upp will recreate it, I had no special configuration in my build method on linux. But now I can't compile anything without adding -std=gnu++11
I didn't have to add anything before. But that still doesn't work, as AtomicWrite() doesn't seem to exist anymore and there seems to be a problem with CallbackNP.i see attachment.

so it sounds like extra flags are needed in the build method that is not put there by default (any more?) in the current version?
But everything compiled right yesterday. Haven't changed anything else.
index.php?t=getfile&id=5024&private=0


  • Attachment: weirdness.png
    (Size: 426.79KB, Downloaded 582 times)
Re: C++11 library features finished [message #46569 is a reply to message #46565] Wed, 01 June 2016 23:24 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13428
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 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1261
Registered: December 2006
Senior 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 #46585 is a reply to message #46584] Fri, 03 June 2016 19:38 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1261
Registered: December 2006
Senior Contributor
Another thing. IMHO, AMap::GetPutPick(const K& k, T&& x) should be renamed into GetPut, and GetPutPick should be deprecated.

TIA


Regards,
Novo
Re: C++11 library features finished [message #46588 is a reply to message #46585] Sat, 04 June 2016 05:36 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1261
Registered: December 2006
Senior 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 148 times)


Regards,
Novo

[Updated on: Sat, 04 June 2016 15:47]

Report message to a moderator

Re: C++11 library features finished [message #46604 is a reply to message #46588] Thu, 09 June 2016 14:05 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13428
Registered: November 2005
Ultimate Member
Thanks, 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).
Re: C++11 library features finished [message #46607 is a reply to message #46604] Fri, 10 June 2016 05:09 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1261
Registered: December 2006
Senior Contributor
mirek wrote on Thu, 09 June 2016 08:05
Thanks, 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
Re: C++11 library features finished [message #46614 is a reply to message #46607] Sat, 11 June 2016 20:55 Go to previous message
mirek is currently offline  mirek
Messages: 13428
Registered: November 2005
Ultimate Member
Thanks, applied as well.
Previous Topic: ide: Optimal mode removed
Next Topic: How You will celebrate 10 000 commit of U++?
Goto Forum:
  


Current Time: Sat Sep 25 09:21:08 CEST 2021

Total time taken to generate the page: 0.01566 seconds