069_comptime4: replace comptime T: type => T: type and refactor a bit accordingly

- replaced instances of `comptime T: type` with `T: type` (080_anonymous_structs)
- left 065_builtins2.zig: 27:// 2. @typeInfo(comptime T: type) @import("std").builtin.Type

see [do not enforce function parameters to be marked comptime if only called at comptime](https://github.com/ziglang/zig/pull/18331)
This commit is contained in:
Ahmed 2024-03-12 21:33:37 +00:00
parent e3877321b6
commit 4b41b0a5c0
3 changed files with 7 additions and 9 deletions

View File

@ -1,11 +1,9 @@
// //
// One of the more common uses of 'comptime' function parameters is // In Zig types are first class values
// passing a type to a function:
// //
// fn foo(comptime MyType: type) void { ... } // fn foo(MyType: type) void { ... }
// //
// In fact, types are ONLY available at compile time, so the // Types are resolved at compile time.
// 'comptime' keyword is required here.
// //
// Please take a moment to put on the wizard hat which has been // Please take a moment to put on the wizard hat which has been
// provided for you. We're about to use this ability to implement // provided for you. We're about to use this ability to implement
@ -42,7 +40,7 @@ pub fn main() void {
// 2) Sets the size of the array of type T (which is the // 2) Sets the size of the array of type T (which is the
// sequence we're creating and returning). // sequence we're creating and returning).
// //
fn makeSequence(comptime T: type, ??? size: usize) [???]T { fn makeSequence(T: type, ??? size: usize) [???]T {
var sequence: [???]T = undefined; var sequence: [???]T = undefined;
var i: usize = 0; var i: usize = 0;

View File

@ -31,7 +31,7 @@ const print = @import("std").debug.print;
// This function creates a generic data structure by returning an // This function creates a generic data structure by returning an
// anonymous struct type (which will no longer be anonymous AFTER // anonymous struct type (which will no longer be anonymous AFTER
// it's returned from the function). // it's returned from the function).
fn Circle(comptime T: type) type { fn Circle(T: type) type {
return struct { return struct {
center_x: T, center_x: T,
center_y: T, center_y: T,

View File

@ -4,9 +4,9 @@
// 2) Sets the size of the array of type T (which is the // 2) Sets the size of the array of type T (which is the
// sequence we're creating and returning). // sequence we're creating and returning).
// //
-fn makeSequence(comptime T: type, ??? size: usize) [???]T { -fn makeSequence(T: type, ??? size: usize) [???]T {
- var sequence: [???]T = undefined; - var sequence: [???]T = undefined;
+fn makeSequence(comptime T: type, comptime size: usize) [size]T { +fn makeSequence(T: type, comptime size: usize) [size]T {
+ var sequence: [size]T = undefined; + var sequence: [size]T = undefined;
var i: usize = 0; var i: usize = 0;