www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Better string representation for TypeSeq used as function arg type?

reply Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
Hello. By executing the following:

alias AS = AliasSeq!(int, double);
int foo(AS td)  // same as int foo(int, double);
{
    writeln(typeof(td).stringof);
    return td[0] + cast(int)td[1];
}

I get:

(int, double)

But it is not very clear as to what exactly the type of `td` is! I 
understand that the AliasSeq is presented to the function body *as if* it 
were a Tuple!(int, double) in that it can be accessed using [0] [1] etc, but 
it is not *really* (in the sense of RTTI) a Tuple, is it? In which case, 
what is it? Is it another "Voldemort" type?

-- 

Dec 12 2015
next sibling parent reply cym13 <cpicard openmailbox.org> writes:
On Saturday, 12 December 2015 at 11:00:17 UTC, Shriramana Sharma 
wrote:
 Hello. By executing the following:

 alias AS = AliasSeq!(int, double);
 int foo(AS td)  // same as int foo(int, double);
 {
     writeln(typeof(td).stringof);
     return td[0] + cast(int)td[1];
 }

 I get:

 (int, double)

 But it is not very clear as to what exactly the type of `td` 
 is! I understand that the AliasSeq is presented to the function 
 body *as if* it were a Tuple!(int, double) in that it can be 
 accessed using [0] [1] etc, but it is not *really* (in the 
 sense of RTTI) a Tuple, is it? In which case, what is it? Is it 
 another "Voldemort" type?
An AliasSeq is a sequence of types that exist only at compile-time, hence I see two possible answers to your question. The first is that it is what you told it to be: a sequence of two elements, first int then double. From the compiler point of view that's what it is. If you look from a runtime point of view though there is no one type for td: it's only a game of symbols and as td by itself doesn't even have a size one could argue that it doesn't have a type at all. That's because it doesn't exist at all at runtime (there is only int and double). So, no, it's not a Voldemort type, it's exactly what the compiler tells you it is: the sequence of types (int, double).
Dec 12 2015
parent Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
cym13 wrote:

 So, no, it's not a Voldemort type, it's exactly what the compiler
 tells you it is: the sequence of types (int, double).
Hmmm it seems to me that if it's not a runtime-valid type, then typeof() shouldn't work at all... --
Dec 12 2015
prev sibling parent reply cym13 <cpicard openmailbox.org> writes:
On Saturday, 12 December 2015 at 11:00:17 UTC, Shriramana Sharma 
wrote:
 [...]
On an another note (please, pardon the double post) I see a lot of your questions lately. This is great, but please post them preferably in then Learn section of the forum where you will get more help, the General section is more for discussing the evolution of D itself.
Dec 12 2015
parent Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
cym13 wrote:

 This is great, but please post them
 preferably in then Learn section of the forum where you will get
 more help, the General section is more for discussing the
 evolution of D itself.
Yes I understand that, but earlier when I asked questions on D.learn about advanced topics like interfacing to C++, I was asked to make them here. So I figured that "elementary" questions go there and more "complex" ones related to "higher" programming topics go here. Since this thread is about metaprogramming which didn't seem an "elementary" topic, I asked it here. I posted some "elementary" questions to D.learn even yesterday... --
Dec 12 2015