template struct question
Ali Çehreli
acehreli at yahoo.com
Wed Feb 12 21:50:44 UTC 2025
On 2/12/25 12:55 PM, WhatMeWorry wrote:
> struct HexBoard(F,I)
> {
> this(F d, I r, I c) {}
> //void displayHexBoard(HexBoard!(F,I) h) {} // this compiles fine!
> }
>
> void displayHexBoard(HexBoard!(F,I) h) {} // error undefined identifier
> F and I
Would isInstanceOf be useful? (Which is actually optional.) It
necessitated two aliases in the struct:
void main()
{
struct HexBoard(F, I)
{
alias Float = F;
alias Int = I;
this(F d, I r, I c) {}
}
import std.traits : isInstanceOf;
void displayHexBoard(HB)(HB h)
if (isInstanceOf!(HexBoard, HB))
{
pragma(msg, "The types are ", HB.Float, " and ", HB.Int);
}
auto h1 = HexBoard!(float,uint)(.25, 3, 7);
displayHexBoard(h1);
}
Ali
More information about the Digitalmars-d-learn
mailing list