Why can't templates use tuples for for argument types?

BCS ao at pathlink.com
Thu Jul 19 10:14:14 PDT 2007


Reply to Bill,


> 
> I don't really understand the point of wanting to be able to specify a
> template argument that could be *anything* -- alias, value, or symbol.
> Other than a big static if, I can't see how you would be able to
> implement any functionality when it could be any one of those things.
> 
> But I'm probably just being dense.
> 
> --bb
> 

One thing that it would be useful for would be a tuple template that does 
something with any tuple type

// take exactly 2 and return true if they are the same
template IsSame(A..,B..){const bool IsSame = ...}

// take 1 or more and remove all of the first from the rest
template Remove(remove.., from...)
{
  static if(from.length == 0)
  {
     alias from Remove;
  }
  else
  {
    staic if(IsSame!(remove, from[0]))
    {
       alias Remove!(remove,from[1..$]) Remove
    }
    else
    {
       alias T!(from[0], Remove!(remove,from[1..$])) Remove
    }
  }
}

this would work as:

Remove!(1,4,5,6,7,1,2,3); // gives (4,5,6,7,2,3)
Remove!(int, byte, short, int, long); // gives (byte, short, long)




More information about the Digitalmars-d-learn mailing list