typedef alternative

Yao G. nospamyao at gmail.com
Sat Aug 14 20:04:25 PDT 2010


I settled this just using an enum value passed as template argument:

---
enum DatePart
{
     Year,
     Month,
     Day,
}

struct DatePartImpl(T : DatePart )
{
     // Insert implementation here...
}

alias DatePartImpl!(DatePart.Year)  Year;
alias DatePartImpl!(DatePart.Month) Month;
alias DatePartImpl!(DatePart.Day)   Day;

void foo( Year y, Month m, Day d ) {}

// Works correctly
foo( Year(2010), Month(8), Day(14) );

// But this isn't allowed
foo( Day(14), Year(2010), Month(8) );
---


-- 
Yao G.


More information about the Digitalmars-d-learn mailing list