Possible reduction of the original.
---
alias AliasSeq(TList...) = TList;
template EnumMembers(E)
{
alias EnumMembers = AliasSeq;
static foreach (M; __traits(allMembers, E))
EnumMembers = AliasSeq!(__traits(getMember, E, M));
}
struct SumType(Ts)
{
mixin(() {
auto s = "enum Cases : ubyte {";
return s ~= "unset}\n";
}());
Cases which;
union {
Ts cases;
}
}
auto caseOfTemplated(alias func, T)(T s) {
final switch (s.which) foreach(CASE; EnumMembers!(T.Cases)) {
case CASE:
return func(s.cases);
}
}
void foo() {
bool validate() {
SumType!(int) s;
caseOfTemplated!(a => typeid(a))(s) == typeid(string);
return true;
}
static assert(validate);
}
Comment #4 by destructionator — 2022-12-20T19:49:44Z
The code that does it is:
// to bypass any opCast that may be present on the original class.
return .opEquals!(Object, Object)(*cast(Object*) &lhs, *cast(Object*) &rhs);
And appears plain `cast() lhs, cast() rhs` instead of the pointer cast will also bypass opCast so i think this is a fairly easy fix.
Comment #5 by dlang-bot — 2022-12-20T19:54:10Z
@schveiguy created dlang/dmd pull request #14726 "fix 23272. CTFE comparison of TypeInfo fails" fixing this issue:
- fix 23272. CTFE comparison of TypeInfo fails
https://github.com/dlang/dmd/pull/14726
Comment #6 by ibuclaw — 2022-12-20T19:55:01Z
(In reply to Iain Buclaw from comment #3)
> Possible reduction of the original.
Which can be hand simplified further to:
---
struct SumType
{
int cases;
}
auto caseOfTemplated(alias func, T)(T s)
{
return func(s.cases);
}
void foo()
{
auto validate()
{
SumType s;
auto t = caseOfTemplated!(a => typeid(a))(s) == typeid(string);
return true;
}
static assert(validate);
}
Comment #7 by ibuclaw — 2022-12-20T19:58:13Z
(In reply to Iain Buclaw from comment #6)
> (In reply to Iain Buclaw from comment #3)
> > Possible reduction of the original.
> Which can be hand simplified further to:
Oh wait, I'm being an idiot.
---
void foo()
{
auto validate()
{
assert(typeid(int) != typeid(string));
return true;
}
static assert(validate);
}
Comment #8 by robert.schadek — 2024-12-07T13:42:13Z