Is there a convention or idiomatic way to be sort of "ergonomirally polymorphic" or agnostic about something being a pointer-to-a-const-T or a T:
pub fn product(values: []const PtrToIntegerOrInteger) Integer {
...
}
I know the default way of writing arguments, like
fn zzz(x: SomeStruct) void { } you're saying you're agnostic to whether the compiler decides to pass you a reference pointer or copy-by-value-- (do I understand that correctly?)
I'm looking for something like that but for more complex types, like the above. Sometimes I have slices of pointers, sometimes I have slices of direct structs, and for functions like the above where I'm not going to do anything but read out the values I don't really care about the difference.
I know I can take anytype and do comptime checks on it, but it feels like it would lead to duplication of code, as I'd have two near-identical functions, one for each such case? only some p.mul(el) and p.mul(&el) difference, and copy-pasted code leads to errors as I change one and forget to change the other, etc. (this might look trivial, above, but it uses a better algorithm than the naive one to multiply balanced values..) Any way to comptime this without duplicating code? Also have many such functions, sums, polymul, convolutions, etc.
And/or wondering if I'm going about it all wrong and the idiomatic way to handle this is way different?
(Of course I don't want anything runtime, like a tagged union.. I essentially want the compiler to compile two versions of the function, one thinking that T is a pointer, one thinking T is a value.)