www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - TypeTuple of functions

reply bearophile <bearophileHUGS lycos.com> writes:
I'm asking questions all the time :-)

I have just closed this bug report as fixed:
http://d.puremagic.com/issues/show_bug.cgi?id=5695

Using that idiom I've seen a difference:


template TypeTuple(TList...) {
    alias TList TypeTuple;
}

double f1(in double x) pure nothrow { return x; }
alias TypeTuple!(f1) funcs1;

alias TypeTuple!(function(in double x) pure nothrow { return x; }) funcs2;

void main() {
    pragma(msg, typeid(typeof(funcs1[0])).stringof); //
&D18TypeInfo_FNaNbxdZd6__initZ
    pragma(msg, typeid(typeof(funcs2[0])).stringof); //
&D22TypeInfo_PFNaNbNfxdZxd6__initZ
}


Do you know what's the difference between those two functions? (I am not able
to read mangled names).

Bye and thank you,
bearophile
Jan 26 2012
next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Thu, Jan 26, 2012 at 01:32:35PM -0500, bearophile wrote:
[...]
 template TypeTuple(TList...) {
     alias TList TypeTuple;
 }
 
 double f1(in double x) pure nothrow { return x; }
 alias TypeTuple!(f1) funcs1;
 
 alias TypeTuple!(function(in double x) pure nothrow { return x; }) funcs2;
 
 void main() {
     pragma(msg, typeid(typeof(funcs1[0])).stringof); //
&D18TypeInfo_FNaNbxdZd6__initZ
     pragma(msg, typeid(typeof(funcs2[0])).stringof); //
&D22TypeInfo_PFNaNbNfxdZxd6__initZ
 }
 
 
 Do you know what's the difference between those two functions? (I am not able
to read mangled names).
[...] You could just use: writeln(typeid(typeof(...))); instead; it gives you readable names. I modified your code and ran it, and got: double() const(double)()* T -- Computers are like a jungle: they have monitor lizards, rams, mice, c-moss, binary trees... and bugs.
Jan 26 2012
prev sibling parent "Daniel Murphy" <yebblies nospamgmail.com> writes:
Differing part:
 FNaNb  xdZ d6
PFNaNbNfxdZxd6

P -> pointer
Nf ->  safe
x -> const

The second one is a function pointer not a function, is inferred to be 
 safe, and inferred to return const(double).


"bearophile" <bearophileHUGS lycos.com> wrote in message 
news:jfs683$2mqh$1 digitalmars.com...
 I'm asking questions all the time :-)

 I have just closed this bug report as fixed:
 http://d.puremagic.com/issues/show_bug.cgi?id=5695

 Using that idiom I've seen a difference:


 template TypeTuple(TList...) {
    alias TList TypeTuple;
 }

 double f1(in double x) pure nothrow { return x; }
 alias TypeTuple!(f1) funcs1;

 alias TypeTuple!(function(in double x) pure nothrow { return x; }) funcs2;

 void main() {
    pragma(msg, typeid(typeof(funcs1[0])).stringof); // 
 &D18TypeInfo_FNaNbxdZd6__initZ
    pragma(msg, typeid(typeof(funcs2[0])).stringof); // 
 &D22TypeInfo_PFNaNbNfxdZxd6__initZ
 }


 Do you know what's the difference between those two functions? (I am not 
 able to read mangled names).

 Bye and thank you,
 bearophile 
Jan 26 2012