| ... | ... | @@ -476,15 +476,19 @@ pub fn hasUniqueRepresentation(comptime T: type) bool { |
| 476 | 476 | else => return false, // TODO can we know if it's true for some of these types ? |
| 477 | 477 | |
| 478 | 478 | .AnyFrame, |
| 479 | | .Bool, |
| 480 | 479 | .BoundFn, |
| 481 | 480 | .Enum, |
| 482 | 481 | .ErrorSet, |
| 483 | 482 | .Fn, |
| 484 | | .Int, // TODO check that it is still true |
| 485 | 483 | .Pointer, |
| 486 | 484 | => return true, |
| 487 | 485 | |
| 486 | .Bool => return false, |
| 487 | |
| 488 | // The padding bits are undefined. |
| 489 | .Int => |info| return (info.bits % 8) == 0 and |
| 490 | (info.bits == 0 or std.math.isPowerOfTwo(info.bits)), |
| 491 | |
| 488 | 492 | .Array => |info| return comptime hasUniqueRepresentation(info.child), |
| 489 | 493 | |
| 490 | 494 | .Struct => |info| { |
| ... | ... | @@ -525,14 +529,10 @@ test "std.meta.trait.hasUniqueRepresentation" { |
| 525 | 529 | |
| 526 | 530 | testing.expect(hasUniqueRepresentation(TestStruct3)); |
| 527 | 531 | |
| 528 | | testing.expect(hasUniqueRepresentation(i1)); |
| 529 | | testing.expect(hasUniqueRepresentation(u2)); |
| 530 | | testing.expect(hasUniqueRepresentation(i3)); |
| 531 | | testing.expect(hasUniqueRepresentation(u4)); |
| 532 | | testing.expect(hasUniqueRepresentation(i5)); |
| 533 | | testing.expect(hasUniqueRepresentation(u6)); |
| 534 | | testing.expect(hasUniqueRepresentation(i7)); |
| 535 | | testing.expect(hasUniqueRepresentation(u8)); |
| 536 | | testing.expect(hasUniqueRepresentation(i9)); |
| 537 | | testing.expect(hasUniqueRepresentation(u10)); |
| 532 | inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| { |
| 533 | testing.expect(hasUniqueRepresentation(T)); |
| 534 | } |
| 535 | inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| { |
| 536 | testing.expect(!hasUniqueRepresentation(T)); |
| 537 | } |
| 538 | 538 | } |