mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 16:24:51 +00:00
std.meta.hasUniqueRepresentation: better support packed structs
This commit is contained in:
parent
d74180c373
commit
db75a8781b
@ -1200,6 +1200,8 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
|
||||
.Array => |info| hasUniqueRepresentation(info.child),
|
||||
|
||||
.Struct => |info| {
|
||||
if (info.layout == .@"packed") return @sizeOf(T) * 8 == @bitSizeOf(T);
|
||||
|
||||
var sum_size = @as(usize, 0);
|
||||
|
||||
inline for (info.fields) |field| {
|
||||
@ -1245,6 +1247,19 @@ test hasUniqueRepresentation {
|
||||
|
||||
try testing.expect(!hasUniqueRepresentation(TestStruct5));
|
||||
|
||||
const TestStruct6 = packed struct(u8) {
|
||||
@"0": bool,
|
||||
@"1": bool,
|
||||
@"2": bool,
|
||||
@"3": bool,
|
||||
@"4": bool,
|
||||
@"5": bool,
|
||||
@"6": bool,
|
||||
@"7": bool,
|
||||
};
|
||||
|
||||
try testing.expect(hasUniqueRepresentation(TestStruct6));
|
||||
|
||||
const TestUnion1 = packed union {
|
||||
a: u32,
|
||||
b: u16,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user