| ... | ... | @@ -312,6 +312,38 @@ test "std.meta.trait.isNumber" { |
| 312 | 312 | testing.expect(!isNumber(NotANumber)); |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | pub fn isIntegral(comptime T: type) bool { |
| 316 | return switch (@typeInfo(T)) { |
| 317 | .Int, .ComptimeInt => true, |
| 318 | else => false, |
| 319 | }; |
| 320 | } |
| 321 | |
| 322 | test "isIntegral" { |
| 323 | testing.expect(isIntegral(u32)); |
| 324 | testing.expect(!isIntegral(f32)); |
| 325 | testing.expect(isIntegral(@TypeOf(102))); |
| 326 | testing.expect(!isIntegral(@TypeOf(102.123))); |
| 327 | testing.expect(!isIntegral(*u8)); |
| 328 | testing.expect(!isIntegral([]u8)); |
| 329 | } |
| 330 | |
| 331 | pub fn isFloat(comptime T: type) bool { |
| 332 | return switch (@typeInfo(T)) { |
| 333 | .Float, .ComptimeFloat => true, |
| 334 | else => false, |
| 335 | }; |
| 336 | } |
| 337 | |
| 338 | test "isFloat" { |
| 339 | testing.expect(!isFloat(u32)); |
| 340 | testing.expect(isFloat(f32)); |
| 341 | testing.expect(!isFloat(@TypeOf(102))); |
| 342 | testing.expect(isFloat(@TypeOf(102.123))); |
| 343 | testing.expect(!isFloat(*f64)); |
| 344 | testing.expect(!isFloat([]f32)); |
| 345 | } |
| 346 | |
| 315 | 347 | pub fn isConstPtr(comptime T: type) bool { |
| 316 | 348 | if (!comptime is(.Pointer)(T)) return false; |
| 317 | 349 | return @typeInfo(T).Pointer.is_const; |