How about a special null template parameter?
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Sat Aug 20 03:04:07 PDT 2016
On 20.08.2016 00:07, Engine Machine wrote:
> On Friday, 19 August 2016 at 21:07:42 UTC, Timon Gehr wrote:
>> On 19.08.2016 20:25, Engine Machine wrote:
>>> So we can create types relationships easier:
>>>
>>> class Type(T) : Type!null
>>> {
>>> int x;
>>> static if (T is Dog)
>>> int y;
>>
>>
>> alias Seq(T...)=T;
>>
>> template TypeParent(T...) if(T.length==1){
>> static if(is(typeof(T[0])==typeof(null))) alias TypeParent = Seq!();
>> else alias TypeParent = Seq!(Type!null);
>> }
>>
>> class Type(T...): TypeParent!T if(T.length==1){
>> int x;
>> static if (T is Dog)
>> int y;
>> }
>
> This is a bit verbose
Apart from the workaround for the ridiculous alias template parameter
semantics, I think the length of the code more or less matches the
specificity of the requested behaviour. (There should be ways to
abstract out most of it, in case you need this really often.)
> and not quite right (T is Dog should be something
> like T[0], or whatever).
> ...
('T is Dog' does not work anyway.)
> It does essentially work. My only complaint is that it would be nice to
> be able to export an alias to Type!() = Type; in the namespace of the
> type being created. Doubt that D can do that!? If it can, then it should
> be an adequate solution.
>
> That is
>
> It would be nice to have something like
>
> alias Type = Type!();
> class Type(T...): TypeParent!T if(T.length==1){
> int x;
> static if (T is Dog)
> int y;
> }
I don't understand how this is related.
More information about the Digitalmars-d
mailing list