Template Question
Bill Baxter
dnewsgroup at billbaxter.com
Mon Apr 14 23:24:27 PDT 2008
Bill Baxter wrote:
> Mike Parker wrote:
>> Bill Baxter wrote:
>>> Mike Parker wrote:
>>>> Mike Parker wrote:
>>>>> Bill Baxter wrote:
>>>>>> Mike Parker wrote:
>>>>>>> Bill Baxter wrote:
>>>>>>>> Mike Parker wrote:
>>>>
>>>>>
>>>>> This is exactly what I was looking for. I don't understand it, but
>>>>> it works.
>>>>
>>>> Actually, it doesn't work.
>>>
>>> Ok, so in that case...
>>> I think you can put an alias for the type inside an interface, and
>>> use that to work around:
>>>
>>> interface Foo(T)
>>> {
>>> alias T TheType;
>>> void init(T);
>>> }
>>>
>>> ...
>>> static if ( is(U : Foo!(U.TheType)) ) {
>>> ...
>>> }
>>>
>>> That seems to work.
>>>
>>
>> Yes, this works. But, the static if evaluation never completes if U
>> does not have TheType. It craps out with errors as soon as U.TheType
>> is encountered rather than printing out the more friendly static assert.
>
> I don't understand. Can't you just make it
>
> static assert(is(U : Foo!(U.TheType))),
> "Use a Foo!() don't be a Foo! -- Mr. T");
Maybe you've found another bug?
Expressions inside an "is" should never cause an error unless they're
syntactically mal-formed, so if you're saying you're getting an actual
error from the expression inside the static assert then that's a problem.
But in that case I think you can work around with:
static if (is(U.TheType)) {
static assert(is(U : Foo!(U.TheType))),
"Use a Foo!() don't be a Foo! -- Mr. T");
} else {
static assert(false, "No .TheType so that can't be a Foo");
}
--bb
More information about the Digitalmars-d-learn
mailing list