www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Compare AliasSeq isn't working

reply Chris Katko <ckatko gmail.com> writes:
I'm trying this idea for an API style it's... not quite working. 
The part I'm failing at currently is actually classifying types 
passed in.

I want this to occur at compile time.

void funct(A...)(A a)
	{
	static if (a.length)
		{
		writeln(a[0]); //first is "pos(100,100)"
		static if(
			is(a[0] == pos) //<---never matches
			)
			{
			writeln(a[0].x); //works, as "pos.x"
			writeln(a[0].y);
			}
		
                 static if (a.length > 1)
                      funct(a[1 .. $]);
		}
	}

struct pos { float x, y; }
struct scale { float f; }
struct rotate { float a; }

void test_inst()
	{
	funct(pos(100,100), scale(2), rotate(0.0f));
	}


I've tried all kinds of variations of test conditions. I've tried 
wrapping the right side in an AliasSeq. I've tried quotation 
marks. I've tried other stuff. I can't find any applicable posts 
or examples online.

All I want to do is (at this point anyway):

   - Pass a variable number of arguments (works), match them 
(FAIL), and read their interal values. (works)

At compile time.

Thanks.
Mar 27 2018
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 03/27/2018 11:11 PM, Chris Katko wrote:

          writeln(a[0]); //first is "pos(100,100)"
          static if(
              is(a[0] == pos) //<---never matches
It's because not a[0] but its *type* is pos: is(typeof(a[0]) == pos) //<---MATCHES! :) Ali
Mar 27 2018
parent Chris Katko <ckatko gmail.com> writes:
On Wednesday, 28 March 2018 at 06:20:56 UTC, Ali Çehreli wrote:
 On 03/27/2018 11:11 PM, Chris Katko wrote:

          writeln(a[0]); //first is "pos(100,100)"
          static if(
              is(a[0] == pos) //<---never matches
It's because not a[0] but its *type* is pos: is(typeof(a[0]) == pos) //<---MATCHES! :) Ali
That's perfect!!! THANKS!!!!
Mar 27 2018