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 » U++ Library support » U++ Core » NEW: generic Toupel grouper
Re: NEW: generic Toupel grouper [message #29389 is a reply to message #29349] Mon, 18 October 2010 10:00 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
ok i get it. this one is then possible
	Tuple2<int, const char *> data = { 1, "Kvuli" };

, though its a bit more verbose then
Tuple2<int, const char*>(1,"Kvuli);
Re: NEW: generic Toupel grouper [message #29391 is a reply to message #29389] Mon, 18 October 2010 11:12 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

kohait00 wrote on Mon, 18 October 2010 10:00

ok i get it. this one is then possible
	Tuple2<int, const char *> data = { 1, "Kvuli" };

, though its a bit more verbose then
Tuple2<int, const char*>(1,"Kvuli);


The idea is that with Tuple2<...>(a,b) you can't fill the arrays easily, as Mirek was pointing out.

I have read more about the requirements for type to be POD. If I understand right, then the only thing preventing Tuple from being POD and Moveable same time is the inheritance from Moveable. So that leaves us with two options: Either declare the friend void AssertMoveable0(T* ) directly in the Tuple struct or doing it outside with (something like) NTL_MOEABLE(). The first approach is troublesome because it is not easy to do that only for tuples with moveable contents. The second option is useless too, since outside of the template is no chance to do it automaticaly, as the template parameters are not known.

Also there might be one more possibility. Is it possible to mark class moveable in other class? If I am not mistaken the entire trick is to make the compiler instantiate the AssertMoveable0(T*). So I would expect something like this to work too:
template<class A,class B>
struct helper__Tuple2<A,B>:PossiblyMoveable<Tuple2<A,B>,A,B>{}
The helper class should mark Tuple2 as moveable (using the template metaprograming from my last post), while the Tuple2 itself would stay POD. But for some reason I couldn't get it to work so far Confused Any hints?

Honza
Re: NEW: generic Toupel grouper [message #29392 is a reply to message #29391] Mon, 18 October 2010 12:12 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
maybe this is sexy enough Smile
it goes just below the TupleX classes respectively, in the Tuple.h


template<class A, class B>
inline void AssertMoveable0(Tuple2<A,B>*) { AssertMoveable<A>(); AssertMoveable<B>(); }



the function only instantiates when Tuple is used inside a container, which needs Moveable<> of TupleX. thus this functions checks if the components are moveable as well, complaining if not, just as usual.

the user wouldn't to care at all.

it at least compiles well for MSC9 and TDMGCC 440, TDMGCC451 and MINGW 440

[Updated on: Mon, 18 October 2010 12:13]

Report message to a moderator

Re: NEW: generic Toupel grouper [message #29394 is a reply to message #29392] Mon, 18 October 2010 13:25 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

"kohait00 wrote"

maybe this is sexy enough
it goes just below the TupleX classes respectively, in the Tuple.h
template<class A, class B>
inline void AssertMoveable0(Tuple2<A,B>*) { AssertMoveable<A>(); AssertMoveable<B>(); }


Yes, that is elegant and simple. Much better than anything I coud think of... Embarassed I don't see any trouble with it, wonder if Mirek will Smile

Honza
Re: NEW: generic Toupel grouper [message #29421 is a reply to message #29392] Tue, 19 October 2010 15:21 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Mon, 18 October 2010 06:12

maybe this is sexy enough Smile
it goes just below the TupleX classes respectively, in the Tuple.h


template<class A, class B>
inline void AssertMoveable0(Tuple2<A,B>*) { AssertMoveable<A>(); AssertMoveable<B>(); }



the function only instantiates when Tuple is used inside a container, which needs Moveable<> of TupleX. thus this functions checks if the components are moveable as well, complaining if not, just as usual.

the user wouldn't to care at all.

it at least compiles well for MSC9 and TDMGCC 440, TDMGCC451 and MINGW 440


EXCELLENT idea!

Applied, I guess we can now consider Tuples complete. Thanks!

Mirek
Re: NEW: generic Toupel grouper [message #30084 is a reply to message #29421] Tue, 07 December 2010 15:59 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
this should speed things up a bit, isn't it?

Tuple.h:30, 65, 102
	Tuple3<A, B, C> r = { a, b, c };

instead of

	Tuple3<A, B, C> r;
	r.a = a;
	r.b = b;
	r.c = c;

Re: NEW: generic Toupel grouper [message #30086 is a reply to message #30084] Tue, 07 December 2010 21:44 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Tue, 07 December 2010 09:59

this should speed things up a bit, isn't it?

Tuple.h:30, 65, 102
	Tuple3<A, B, C> r = { a, b, c };

instead of

	Tuple3<A, B, C> r;
	r.a = a;
	r.b = b;
	r.c = c;




Sorry, but nonsense. No speedup, and there are (AFAIK) some pretty restrictive rules about {} initialization in C++...
Previous Topic: Date limited to 2020 and 2015 does not work ?!?
Next Topic: Value question (memory consumption)
Goto Forum:
  


Current Time: Sat Apr 27 17:25:18 CEST 2024

Total time taken to generate the page: 0.02408 seconds