#default arguments in zig?

1 messages · Page 1 of 1 (latest)

solemn delta
#

not in the traditional sense, no, you can't do fn foo(bar: u32 = 0) void {} or anything

#

but you can use structs with default field values to supplement this where appropriate

#

e.g.

fn foo(args: struct { bar: u32 = 0 }) void {}
late lodge
#

ah

#

so i can use .{}

solemn delta
#

and thus foo can be called either like foo(.{}), or like foo(.{ .bar = n })

#

ye

late lodge
#

is there a way to.. do like if typeof(x) == int do

solemn delta
#

ye, you could do if (@typeInfo(@TypeOf(x)) == .Int)

#

dunno what that has to do with default args though

#

is there something specific you're trying to do?

late lodge