Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread bearophile
%u: If I have an alias F that represents a function, is there any way for me to create a function func() whose signature is exactly the same as that of F? In theory this has to be enough: typeof(F) F2; Bye, bearophile

Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread %u
In theory this has to be enough: typeof(F) F2; But in practice, I want to change the body of my function, or possibly add new parameters in the beginning or the end. Does this let me do either of these? Thank you!

Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread Andrej Mitrovic
Is this what you're looking for?: import std.stdio; import std.traits; void test(alias F)() { ReturnType!(F) otherFunc(ParameterTypeTuple!(F)) { typeof(return) result; return result; } } double foo(int x, int y) { double result; return x + y * 2.5; } void

Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread Andrej Mitrovic
Sorry, here's a more complete example: import std.stdio; import std.traits; void test(alias F)(int x, int y) { ReturnType!(F) otherFunc(ParameterTypeTuple!(F) args) { typeof(return) result; result = args[0] + args[1] * 2.5; return result; }

Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread Andrej Mitrovic
Better: void test(alias F)(ParameterTypeTuple!(F) args) { ReturnType!(F) otherFunc(ParameterTypeTuple!(F) args) { typeof(return) result; result = args[0] + args[1] * 2.5; return result; } return otherFunc(args); } double foo(int x, int y) { double

Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread Andrej Mitrovic
Holy cow is that a bug? It's returning a value even though it's a void function.

Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread Andrej Mitrovic
Never mind my stupid build script didn't recompile and it ran an old version. Fixed: import std.stdio; import std.traits; auto test(alias F)(ParameterTypeTuple!(F) args) { ReturnType!(F) otherFunc(ParameterTypeTuple!(F) args) { typeof(return) result; result = args[0] +

Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread Jacob Carlborg
On 2011-01-19 16:29, Andrej Mitrovic wrote: Is this what you're looking for?: import std.stdio; import std.traits; void test(alias F)() { ReturnType!(F) otherFunc(ParameterTypeTuple!(F)) { typeof(return) result; return result; } } double foo(int x, int y) {

Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread Andrej Mitrovic
I never thought of that. There's a ParameterStorageClassTuple template, but I don't see a template that combines both of these templates to duplicate the exact signature. Something like that should probably be added to Phobos.

Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread %u
Is this what you're looking for?: No. :) (Though you already found this out at the end!) I was looking for some way to keep the storage classes and any other (meta)data about the parameters that may be added in the future to the library. I have a feeling this might be a very big change in how

Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread Andrej Mitrovic
On 1/19/11, %u wfunct...@hotmail.com wrote: Is this what you're looking for?: No. :) (Though you already found this out at the end!) I was looking for some way to keep the storage classes and any other (meta)data about the parameters that may be added in the future to the library. I have a

Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread Jacob Carlborg
On 2011-01-19 18:28, %u wrote: Is this what you're looking for?: No. :) (Though you already found this out at the end!) I was looking for some way to keep the storage classes and any other (meta)data about the parameters that may be added in the future to the library. I have a feeling this

Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread wrzosk
A little example ... import std.stdio; import std.traits; import std.typetuple; import std.metastrings; alias ParameterStorageClassTuple PSCT; alias ParameterStorageClass PSC; alias ParameterTypeTuple PTT; string ToStorageName(alias T)() { static if(T == PSC.REF) return ref; else static

Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread %u
The ugly solution would be to do this: void test (ref int a) { } void main () { writeln(typeof(test).stringof); } Which will print: void function(ref int a) and then parse out what you need. If you're referring to using mixin() to parse the signature, I've already thought of that, but it

Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread Andrej Mitrovic
On 1/20/11, %u wfunct...@hotmail.com wrote: No... why? ref would be just like const -- so your parameter's data type could be ref(const(string)). ref(const(immutable(string)[])) ? That's crazy! Anyway I don't really know what we're talking about anymore. :) s/we're/I'm The string mixin

Re: Exactly Replicating a Function's Signature?

2011-01-19 Thread %u
ref(const(immutable(string)[])) ? That's crazy! Did you mean ref(const(immutable(char)[]))?? :] Haha... well it was just an idea on how to add the functionality, and like I mentioned, even if it was fine for 'ref' and 'lazy', it wouldn't make any sense for 'out' anyway, so I'd say screw my