template<class T>
struct NativeTypeWrap
{
typedef somePersonalType someType;
T val;
operator const T&() { return val; }
T& operator =(const T& v) { val = v; return val; }
};
typedef NativeTypeWrap<short> u16;
using a class instead of a type
I was thinking, is there a way for me to have a class that works exactly like a type with no performance lost? here is an example
^ that is untested but its something i like to do. The idea is it works exactly like short does in every way except i am attaching typedefs to it for overloading reasons. I have a class that doesnt want ints but specific size structs which can be ints but would need a typedef. I'd like the code to fail if i pass in an type that doesnt have those typedefs in it (so i know if i goofed up).
Classes ARE types. You mean "... instead of a primitive", or perhaps "instead of a typedef".
And in C++, there is no likely performance loss for this kind of thing, certainly not in release mode.
And in C++, there is no likely performance loss for this kind of thing, certainly not in release mode.
Yeah, i want something used like a type_traits but this would hold different data.
What i mainly wanted to know is if something would bite me in the ass while doing this.
also, i need to implement each and every operator overload? or is there a way to only implement a few which would carry out the rest? maybe i can inherit something that already does this?
What i mainly wanted to know is if something would bite me in the ass while doing this.
also, i need to implement each and every operator overload? or is there a way to only implement a few which would carry out the rest? maybe i can inherit something that already does this?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement