#Stupid question about array as function argument

1 messages · Page 1 of 1 (latest)

oblique oracle
#

It is probably a very simple thing but tried a few thing but they all don't work.

How can I make this work? I want to initialize the array inside the parameter list.

array.containsAny([]const u8, args_arr, [2][]const u8{"-h", "-help"})
acoustic urchin
#

I don't quite understand the question...
do you know how to write the solution in a different language, and we'll translate?

celest stirrup
#

I understand the question?

#

I don't see why it doesn't work though

#

what's the error?

oblique oracle
celest stirrup
#

oh, you probably want to use &

#

just add & before it

oblique oracle
#

If I put it in front it will give me a different error

celest stirrup
#

which error?

oblique oracle
celest stirrup
#

that seems like a standard library issue

oblique oracle
#

I got it

#

I wrap it in @constCast() and that works

celest stirrup
#

just set the array to a variable before it

#

no need to use @constCast

oblique oracle
celest stirrup
#

well it's better to do that than use @constCast

oblique oracle
#

ok

#

I intended to use it only in that function as a parameter and don't have it available for the rest of the main function.

#

but if that's not possible without constCast then I just have to deal with it

celest stirrup
#

I mean you can use constCast if you want but it's not a good look

#

I doubt that method does modify it

latent arch
#

just change the function signature? its in your src

celest stirrup
#

oh lol

#

thought it was std

#

yea do that

oblique oracle
#

oh, it was as simple at []T => []const T

acoustic urchin
oblique oracle
oblique oracle
acoustic urchin
#

yeah, the comparison function you need is different

#

they'll just compare the pointers and lengths or something...

latent arch
#

comparing slices with == is explicitly disallowed, i assume to not misguide people into thinking its a deep comparison