#Generics and Overloaded Functions

1 messages · Page 1 of 1 (latest)

hot quest
#

After testing, seems Zig doesn't have overloaded functions. Is there a way for handling implementing generics/templates? For example, writing a function that takes a union type argument that subtypes can be cast into.

An example is writing a function that can print an array by taking one of any numeric type, not just u8

fn generic_print(arr: []u8);
#

Generics and Overloaded Functions

hallow dome
noble kestrel
#

Zig doesn't support function overloading but you can use anytype type, then using type introspection assert whether correct arguments have been supplied