On Friday, 9 June 2017 at 05:53:11 UTC, ag0aep6g wrote:
...
Get rid of `real val;` and just compare `payload`s. For classes, you can detect them with `static if (is(T == class))` or some such, and cast to void* when comparing.

But when you cast to void*, you're ignoring an opEquals or opCmp the class might have. That might be surprising. So maybe just require that classes implement opCmp. Or try to detect when a class doesn't have opCmp and only cast then.


Possibly. but I can't use those methods on primitive types. Also, I tried implementing a internal method to determine if it is a class, or primitive, and compare based off of mem location, or actual value.

For some reason, the compiler didn't care, telling me that I can't just compare two classes with < or > operators, even though I thought I seperated that code out for primitives only.

This is why I'm converting the addresses to real numbers. Which means that I have to do the same to the primitive types. I also tried using 2 different constructors, with the idea of doing all that casting stuff in there. But that didn't bode well with the compiler. It didn't know which one to use, as both are entering as type T.

I then tried to implement a typeid check, I thought that would work, but even though I had said if typeid.toString() was in ["int", "float", ... ] call primitive func, else call class func, the compiler complained that I can't throw classes into the logic of the first function. Which wasn't even possible, because it wouldn't pass the type check that I made.


Also, I don't want to require that classes implement an opEquals. I want to use this with other people's classes, as well as built-in classes. That would cause problems.

And it wouldn't bypass the whole primitives/class-struct problem.

Thanks though.

Maybe Ill just go with my inheritance idea, and have one for primitives, and one for classes.

Reply via email to