• Advertisement
Sign in to follow this  

Any class with operator overloads

This topic is 1895 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Wouldn't it be handy to have CScriptAny have operator overloads for at least the basic types so you can do:
any x = 100;

Has anyone done that already?

Share this post


Link to post
Share on other sites
Advertisement
I may be mistaken (I've never used the any class), but isn't its intended use for parameters to application functions? I can't think of a situation when it would be good practice to use it otherwise. Edited by Jake Albano

Share this post


Link to post
Share on other sites
I want to do this:

any[] list = { 0, "string", someObject, 4.0f };

So I want "any" to overload = for the basic types.

Share this post


Link to post
Share on other sites
You can certainly implement an opAssign method for each of the basic types you want to support.

The method would have to look up the type id of the value. This could be done once and cached so you don't have a performance hit for each assignment. Edited by Andreas Jonsson

Share this post


Link to post
Share on other sites
OK thanks, will do. Just thought somebody has already done that. I can show the results when it's working.

Share this post


Link to post
Share on other sites
One more thing. I'd like to do this:

SomeFunc( { x, y, "test } );

where void SomeFunc( any[]@ ) or void SomeFunc( any[] )

If you know actionscript, I think you know where I'm heading.
Anyway I could accomplish this?

Share this post


Link to post
Share on other sites
I have this on my to-do list already. I'm not sure when I'll have the time to implement it though.

It will require quite a bit of change in the compiler in order to handle this scenario. The compiler would have to defer the evaluation of the array until it knows where it will be used so it can determine the exact type of the array object and initialize it appropriately.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement