#Is there a way to differentiate type aliases at comptime?

1 messages · Page 1 of 1 (latest)

lethal locust
#

I know typedefs are not a thing, but is there a workaround to get aliased names at comptime?

const A = u32;
const B = u32;
@typeName(A) == @typeName(B)
short crypt
#

enum (u32) {_}

#

that's the common pattern for creating opaque integer types

lethal locust
#

ah, unfortunately that was just an example, Id like to alias structs

median maple
#

I think const U = @Type(@typeInfo(T)) would create a distinct type

#

no decls though ofc

lethal locust
#

hmm yes it does. i think i can workaround that. thanks.

sharp cliff
#

you can discard the decls

const U = comptime blk: {
  var ti = @typeInfo(T);
  ti.decls = &.{};
  break :blk @Type(ti);
};

just so it's guaranteed to alias any type

lethal locust
#

perfect! exactly what I needed. small detail, just had to use ti.Struct.decls = &.{};

#

thank you, i really apprecite it