Just what it says in the title. I know you can't register template methods on objects, but it's recently occurred to me that cast appears to use a templated function. Is that something that's built into the language, or can it be repeated in user code?
I'm working on a few classes that expose reflection to the scripting language, and currently I've got it set up like this:
I have a Type class, which has no default factory. It requires a parameter of type __typeof.
I have a Typeof class, which is registered with the engine as both __typeof and typeof<T>.
typeof<T> is implicitly convertable to __typeof.
__typeof has no factory defined at all, so it can only be created from an instance of typeof<T>.
It's a convoluted setup, but ultimately it allows me to do this:
What I'm wondering now is whether I can make a function that behaves in the same way as cast<T>(), with the end result being a syntax that looks like this:
Type myType = typeof<MyClass>();
Of course, the best possible result would be to mimic C# syntax exactly, but I don't think that's possible;
Type myType = typeof(MyClass);