BitArray/BitFields - Reworking with templates

Era Scarecrow rtcvb32 at yahoo.com
Mon Jul 30 14:19:10 PDT 2012


On Monday, 30 July 2012 at 20:48:26 UTC, Philippe Sigaud wrote:
>> Now if all that is correct, say I want to make two functions 
>> that both use X, but are not compatible, but template 
>> functions will allow it. So...
>
> I'm not sure I understand what you're trying to do. Do you mean 
> you want a function that accept X!(T)s for any T, and not any 
> other type?

  Anything of template X! previous post of mine shows sort of an 
example.

> struct X(T) {}
>
> void func(T)(X!T x)
> {}
>
> void main()
> {
>     X!bool b;
>     X!int i;
>     func(b);
>     func(i);
> }

  Hmmm i do think that seems right... but if it contains multiple 
parameters, then...?

template X(x1, x2, x3) {
  struct XT {}
}

> void func(T)(X!T x) {}
Will this still work?

> Here you want a constraint that checks that U and T are both
> X!(SomeType) or an XY?

  As before, of Template X, and struct XY, but T (or sometype) 
doesn't matter.

> void tempFunc(T,U)(T t, U u) if (is(T a == X!(SomeType), 
> SomeType) &&
> is(U a == X!(SomeType), SomeType)
>                                                 || is(T == XY) 
> && is(U == XY))
> {
> ...
> }
> Is that what you need?

  I want to say no... But I haven't actually tested it for my use 
cases. Leaving it unconstrained (without checking) to make it 
work is a disaster waiting to happen: I want T and U to both be 
of the same template (X in this case) but not the same 
instantiation arguments.

  I hope I'm not repeating myself too much.


More information about the Digitalmars-d-learn mailing list