mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
Alignment: min/minStrict max/maxStrict
Carve out a path forward for being a little bit more intentional about handling "default" alignment values.
This commit is contained in:
parent
5ea3de55c4
commit
51b1a2a6cb
@ -3178,16 +3178,32 @@ pub const Alignment = enum(u6) {
|
||||
}
|
||||
|
||||
/// Treats `none` as zero.
|
||||
/// This matches previous behavior of using `@max` directly on byte units.
|
||||
/// Prefer `maxStrict` if possible.
|
||||
pub fn max(lhs: Alignment, rhs: Alignment) Alignment {
|
||||
if (lhs == .none) return rhs;
|
||||
if (rhs == .none) return lhs;
|
||||
return maxStrict(lhs, rhs);
|
||||
}
|
||||
|
||||
pub fn maxStrict(lhs: Alignment, rhs: Alignment) Alignment {
|
||||
assert(lhs != .none);
|
||||
assert(rhs != .none);
|
||||
return @enumFromInt(@max(@intFromEnum(lhs), @intFromEnum(rhs)));
|
||||
}
|
||||
|
||||
/// Treats `none` as maximum value.
|
||||
/// Treats `none` as zero.
|
||||
/// This matches previous behavior of using `@min` directly on byte units.
|
||||
/// Prefer `minStrict` if possible.
|
||||
pub fn min(lhs: Alignment, rhs: Alignment) Alignment {
|
||||
if (lhs == .none) return rhs;
|
||||
if (rhs == .none) return lhs;
|
||||
if (lhs == .none) return lhs;
|
||||
if (rhs == .none) return rhs;
|
||||
return minStrict(lhs, rhs);
|
||||
}
|
||||
|
||||
pub fn minStrict(lhs: Alignment, rhs: Alignment) Alignment {
|
||||
assert(lhs != .none);
|
||||
assert(rhs != .none);
|
||||
return @enumFromInt(@min(@intFromEnum(lhs), @intFromEnum(rhs)));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user