Home » U++ Library support » U++ Core » user 'Value' [FEATURE REQUEST]
user 'Value' [FEATURE REQUEST] [message #3437] |
Thu, 25 May 2006 11:04 |
qwerty
Messages: 130 Registered: May 2006
|
Experienced Member |
|
|
one user Value on Arrays etc. It come would handy.
like:
Array<int> ints;
Value ints.userValue;
something like Tag. it could be on other classes, but my knowledge of upp are not so far....
|
|
|
|
|
Re: user 'Value' [FEATURE REQUEST] [message #3455 is a reply to message #3437] |
Thu, 25 May 2006 21:26 |
mr_ped
Messages: 825 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
I think the solution with inheritance is the most easy and usefull one.
template <class T>
class ArrayWithVal : public Array<T>, Moveable< ArrayWithVal<T> > {
public:
Value userValue;
};
(Maybe "MoveableAndDeepCopyOption< ... >" can be used, but Value is just "Moveable", and so I'm not sure if the DeepCopy would be still possible)
I don't think such short piece of code is worth of addition to UPP core. Actually this is the most simple example of what is OOP capable of, and why it has advantages over procedural programming for certain tasks (like this one).
Anyway, I think the "Value" is a good choice in UPP as long as you don't care about it's size in memory (i.e. you will not produce hundrets instances of that class together).
Other common solution is to use void *, or DWORD type.
Both of them allow you to store 32bit ints into user value. The void * is also more understandable if you put there pointer pointing to your custom structure holding more values.
Buth those two are usual for plain C code, and as I said, Value is very good choice in UPP, unless you are memory consumption concerned.
|
|
|
|
|
Goto Forum:
Current Time: Tue Jun 18 06:13:00 CEST 2024
Total time taken to generate the page: 0.02060 seconds
|