Return by 'ref' problems...

Jacob Carlborg doob at me.com
Fri May 4 12:51:40 PDT 2012


On 2012-05-04 16:19, H. S. Teoh wrote:

> Argh... this is really annoying. So I tried all sorts of combinations of
> function pointer syntax in order to get the correct type for a ref
> function that returns const(T), but couldn't. So I decided to let the
> language tell me itself what the type is:
>
> 	import std.stdio;
> 	struct S {}
> 	ref const(S) func() { ... }
> 	void main() {
> 		auto fp =&func;
> 		writeln(typeid(fp));
> 	}
>
> This program outputs:
>
> 	const(test.S)()*
>
> So I copy-n-paste this type into the source:
>
> 	const(test.S)()* fp =&func;

If you use:

writeln(typeof(fp).stringof);

I get this:

const(S) function() ref

Which neither can't be used as a declaration.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list