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 #28396 is a reply to message #28395] Tue, 31 August 2010 15:38 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Tue, 31 August 2010 09:31

MSC i.e. is not even complaining about mistyped template implementations, as long as they are not instantiated. GCC is better here, it checks implementation. but of corse code instantiation is another topic..


Not sure what are you speaking about here.

In any case, I have tested

struct Foo {
	int x;
};

CONSOLE_APP_MAIN
{
	Tuple2<int, Foo> x;
	DDUMP(sizeof(x));
}


and no problems with both GCC and MSC.

Of course adding

      x == x;


invokes errors in both compilers.
Re: NEW: generic Toupel grouper [message #28397 is a reply to message #28396] Tue, 31 August 2010 15:44 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
i was refering to the instantiation of template code itself. MSC does not even syntactically check any template untill it's actually used. gcc does check implementation. both instantiate code only on demand.

so you definitely want to stay with Tupel2, Tupel3... with their explicit implementation instead of generic fourpart Tupel, maybe thats better..

what about then to have more literal names, those Duo, Trio, Quartett? (makes code reading nicer IMO).
Re: NEW: generic Toupel grouper [message #28534 is a reply to message #28397] Mon, 06 September 2010 11:01 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tuple2 - Tuple4 now in Core.

I have added ToString and also "FindTuple" function as compred to posted version.
Re: NEW: generic Toupel grouper [message #29236 is a reply to message #28534] Tue, 12 October 2010 19:41 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Mhhh... it seems to me that Touple hasn't been defined as Moveable, isn't it ?

Would it be possible to make it so :

template <typename A, typename B>
struct Tuple2 :Moveable<Tuple2<A, B> >{


I think tuples are useful inside Vectors and VectorMaps....

Max
Re: NEW: generic Toupel grouper [message #29237 is a reply to message #29236] Tue, 12 October 2010 22:00 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
hi max,

didn,t think of that, but youre right, should be moveable, because main use was inside containers..
Re: NEW: generic Toupel grouper [message #29243 is a reply to message #29237] Wed, 13 October 2010 09:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I am afraid that this is not as easy to make Touple moveable, because that would imply all elements are moveable too, which is not always the case....

It is a little bit troublesome situation. I have no problem requiring all elements to be moveable, however right now I do not see how to add check without breaking POD capability... (the fine method to add check is in destructor, but that would make Touple non-pod).
Re: NEW: generic Toupel grouper [message #29247 is a reply to message #29243] Wed, 13 October 2010 09:32 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
luzr wrote on Wed, 13 October 2010 09:07

I am afraid that this is not as easy to make Touple moveable, because that would imply all elements are moveable too, which is not always the case....

It is a little bit troublesome situation. I have no problem requiring all elements to be moveable, however right now I do not see how to add check without breaking POD capability... (the fine method to add check is in destructor, but that would make Touple non-pod).


I was afraid about that Smile
Anyways, I think that most Tuple usage is, as you said, to spare a struct definition, and usually with moveable content.

A nice way could be some way to make Tuple moveable on request, but I don't know if that can be implemented (and MoveableTuple would be horrible, of course Smile )

Max
Re: NEW: generic Toupel grouper [message #29248 is a reply to message #29243] Wed, 13 October 2010 09:41 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
isnt there any other way to declare TupleX Moveable explicitly whenever its content is Moveable? somehow with template specialisation? so a user wanting to use it in such way simply needs to declare
NTL_MOVEABLE(Tuple2<Foo, Bar>)

and then can use
Vector<Tuple2<Foo, Bar> >


BTW:
i've noticed that the TupleX(const A& a) : a(a) ctors are not used..is there a reason for that? its quite nice to be able to add things like
Array<Tuple<Foo, Bar> > arr;
arr.Add(new Tuple2(foo, bar));
Re: NEW: generic Toupel grouper [message #29253 is a reply to message #29248] Wed, 13 October 2010 11:50 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
found sth to work..


NAMESPACE_UPP

//this would be best, but
//compile ERROR, preprocessor does misunderstand ','
#if 1
NTL_MOVEABLE(Tuple2<Point, Size>);
#endif

//compile ERROR anyway
#if 0
NTL_MOVEABLE((Tuple2<Point, Size>));
#endif

//this DOES compile
#if 0
typedef Tuple2<Point, Size> BLAA;
NTL_MOVEABLE(BLAA);
#endif

//BOTH compile (got MSC9 and TDMGCC)
#if 0
inline void AssertMoveable0(Tuple2<Point, Size> *) {}
#elif 0
template<> inline void AssertMoveable<Tuple2<Point, Size> >(Tuple2<Point, Size> *) {};
#endif

END_UPP_NAMESPACE

....
//cpp


	Vector<Tuple2<Point, Size> > vv;
	
	Tuple2<Point, Size>& tps = vv.Add();
	tps.a.x = 100;
	tps.b.cx = 100;
Re: NEW: generic Toupel grouper [message #29255 is a reply to message #29253] Wed, 13 October 2010 12:24 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
i think the typedef is an easy way, so we can use NTL_MOVEABLE
here a short idea.. if anyone knows how to specify the salt for the name in a better way, welcome..
with this,


//V1
#if 0
#define TUPLE2_MOVEABLE(T1, T2) \
typedef Tuple2<T1,T2> COMBINE3(TD_,T1,T2); \
NTL_MOVEABLE(COMBINE3(TD_,T1,T2)); \

#endif

//V2
#if 1

#define TUPLE2_MOVEABLE(T1, T2, salt) \
typedef Tuple2<T1,T2> TD_salt; \
NTL_MOVEABLE(TD_salt); \

#endif


//V1
#if 0
TUPLE2_MOVEABLE(Point, Size);
#endif

//V2
#if 1
TUPLE2_MOVEABLE(Point, Size, 123);
#endif

//this enables Vector<Tuple2<Point, Size> > to be used
Re: NEW: generic Toupel grouper [message #29263 is a reply to message #29247] Wed, 13 October 2010 18:47 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mdelfede wrote on Wed, 13 October 2010 03:32


A nice way could be some way to make Tuple moveable on request, but I don't know if that can be implemented (and MoveableTuple would be horrible, of course Smile )



MoveableTuple - I do not (yet) know the way how to do that either... Smile (I mean, the correct one).

Well, maybe we should just forget about checking moveability of struct components in this particular case...

Re: NEW: generic Toupel grouper [message #29264 is a reply to message #29255] Wed, 13 October 2010 18:48 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Wed, 13 October 2010 06:24

i think the typedef is an easy way, so we can use NTL_MOVEABLE
here a short idea.. if anyone knows how to specify the salt for the name in a better way, welcome..
with this,


//V1
#if 0
#define TUPLE2_MOVEABLE(T1, T2) \
typedef Tuple2<T1,T2> COMBINE3(TD_,T1,T2); \
NTL_MOVEABLE(COMBINE3(TD_,T1,T2)); \

#endif

//V2
#if 1

#define TUPLE2_MOVEABLE(T1, T2, salt) \
typedef Tuple2<T1,T2> TD_salt; \
NTL_MOVEABLE(TD_salt); \

#endif


//V1
#if 0
TUPLE2_MOVEABLE(Point, Size);
#endif

//V2
#if 1
TUPLE2_MOVEABLE(Point, Size, 123);
#endif

//this enables Vector<Tuple2<Point, Size> > to be used



Too verbose, we need something more sexy...
Re: NEW: generic Toupel grouper [message #29283 is a reply to message #29264] Wed, 13 October 2010 22:03 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
in any case, the user needs to take care of that all by himself. it's just to make the process to do so a bit easier.
but the thing that TupleX needs to be Moveable at least in many cases is important, otherwise usage in Containers would make no sense..

any provisions on that? any more sexy ones Smile
Re: NEW: generic Toupel grouper [message #29284 is a reply to message #29264] Wed, 13 October 2010 22:35 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

luzr wrote on Wed, 13 October 2010 18:48

Too verbose, we need something more sexy...

There is a way... a sexy way Wink What would you say to this:
template <typename A, typename B>
struct Tuple2 : PossiblyMoveable<Tuple2<A,B>,A,B>{
    ... 
}
Is that sexy enough? Smile The idea is that PossiblyMoveable<T,A,B,...> evaluates to Moveable<T> if A,B,... are all moveable and to EmptyClass otherwise.

I can't give you the code right now, but I have it implemented (it needs only some cosmetic changes) and I will post it here tonight or tomorrow. Word of warning in advance: It is heavy "template metaprogramming" Twisted Evil (Just found that term on wiki, but it fits Smile )

kohait00 wrote on Wed, 13 October 2010 22:03

in any case, the user needs to take care of that all by himself. it's just to make the process to do so a bit easier.

As you could already guess from above, what you say is not true Cool It can be done automatically, by abusing the compiler/language just a bit Very Happy

Honza

[Updated on: Wed, 13 October 2010 22:39]

Report message to a moderator

Re: NEW: generic Toupel grouper [message #29287 is a reply to message #29284] Thu, 14 October 2010 02:14 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi,

As I promised, here is the code I mentioned in my previous post...

Disclaimer: I am aware that the implementation is verbose, bulky, tricky, possibly deceiving and abuses compiler to do things it was never meant to do. Yet I am very happy to see the result - simple template that is able to determine moveability of it's parameters.

Majority of the ugly code is in Topt.h. Since U++ uses two different way how to mark a type moveable (Moveable<> and NTL_MOVEABLE), the code has two ugly parts, one checking each method and ORing both together. Also I had to add some more code to NTL_MOVEABLE macro to be able to determine the moveability correctly. In the Tuple.h, the only change is the PossiblyMoveable<> base for each size of Tuple.

PossiblyMoveable might be useful in some other context too. I just can't think of any right now. Also IsMoveable<T> and IsBase<Base,Derived> (can determine if Base is really base class of Derived) could be helpful for someone, but they would need to be little more general for common user to use...

Tell me what you think about this, but don't tell me I'm crazy Twisted Evil I'm actually quite realistic and don't expect this to get into U++. I wrote it mainly for fun of discovering new tricks and pushing the limits Wink

Best regards,
Honza
  • Attachment: Topt.h
    (Size: 19.66KB, Downloaded 163 times)
  • Attachment: Tuple.h
    (Size: 3.19KB, Downloaded 269 times)
Re: NEW: generic Toupel grouper [message #29322 is a reply to message #29287] Fri, 15 October 2010 13:46 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Nice and sexy, but makes Tuple non-POD... Sad

As I said, the problem is not Moveable itself, making it a requirement for Tuple would be non-issue.

The problem is that all possible modifications to TEST that both types are moveable are making Tuple non-POD...

Why we like POD:

	static Tuple2<int, const char *> data[] = {
		{ 1, "Kvuli" },
		{ 2, "Tomuhle" },
	};

Re: NEW: generic Toupel grouper [message #29337 is a reply to message #29322] Fri, 15 October 2010 15:05 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
so it seems as if the user really needs to provide the grain of compiler information that all of TupleX parts are Mouveable..

just need to find a sexy way for that, that is not too verbose..

Re: NEW: generic Toupel grouper [message #29339 is a reply to message #29322] Fri, 15 October 2010 16:24 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

luzr wrote on Fri, 15 October 2010 13:46

Why we like POD:

	static Tuple2<int, const char *> data[] = {
		{ 1, "Kvuli" },
		{ 2, "Tomuhle" },
	};



Smile
Point taken... I'll have to read bit more about how to keep a type POD.
Re: NEW: generic Toupel grouper [message #29342 is a reply to message #29339] Fri, 15 October 2010 17:21 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
one of my questions above seems to be forgotten Smile

Quote:



BTW:
i've noticed that the TupleX(const A& a) : a(a) ctors are not used..is there a reason for that? its quite nice to be able to add things like
Array<Tuple<Foo, Bar> > arr;
arr.Add(new Tuple2(foo, bar));


Re: NEW: generic Toupel grouper [message #29349 is a reply to message #29342] Fri, 15 October 2010 19:50 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Fri, 15 October 2010 11:21

one of my questions above seems to be forgotten Smile

Quote:



BTW:
i've noticed that the TupleX(const A& a) : a(a) ctors are not used..is there a reason for that? its quite nice to be able to add things like
Array<Tuple<Foo, Bar> > arr;
arr.Add(new Tuple2(foo, bar));





The very same reason (POD).
Previous Topic: Date limited to 2020 and 2015 does not work ?!?
Next Topic: Value question (memory consumption)
Goto Forum:
  


Current Time: Fri Apr 19 08:10:53 CEST 2024

Total time taken to generate the page: 0.12723 seconds