digitalmars.D.learn - Compare AliasSeq isn't working
- Chris Katko (37/37) Mar 27 2018 I'm trying this idea for an API style it's... not quite working.
- =?UTF-8?Q?Ali_=c3=87ehreli?= (4/7) Mar 27 2018 It's because not a[0] but its *type* is pos:
- Chris Katko (2/9) Mar 27 2018 That's perfect!!! THANKS!!!!
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
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
On Wednesday, 28 March 2018 at 06:20:56 UTC, Ali Çehreli wrote:On 03/27/2018 11:11 PM, Chris Katko wrote:That's perfect!!! THANKS!!!!writeln(a[0]); //first is "pos(100,100)" static if( is(a[0] == pos) //<---never matchesIt's because not a[0] but its *type* is pos: is(typeof(a[0]) == pos) //<---MATCHES! :) Ali
 Mar 27 2018








 
  
  
  Chris Katko <ckatko gmail.com>
  Chris Katko <ckatko gmail.com>