Proposal: First class types (at compiletime)
H. S. Teoh
hsteoh at qfbox.info
Thu Jul 20 14:46:49 UTC 2023
On Thu, Jul 20, 2023 at 01:44:15PM +0000, Commander Zot via Digitalmars-d wrote:
> wouldn't it be possible to have something like first class types (at
> compile time) to replace tamplates for type logic with regular
> functions executed at CTFE?
>
> the idea is to make this work
> ```
> type_t min(type_t a, type_t b){ return a.sizeof<=b.sizeof?a:b; }
> alias r = min(short, int);
>
> ```
[...]
What are you trying to accomplish that needs to do this? If you
describe your use case, maybe we can better understand why you can't
just use a simple template:
template Min(T, U) {
static if (T.sizeof <= U.sizeof)
alias Min = T;
else
alias Min = U;
}
alias V = Min!(int, short);
static assert(is(V == short));
T
--
Some ideas are so stupid that only intellectuals could believe them. -- George Orwell
More information about the Digitalmars-d
mailing list