253

With a bit of fiddeling you can use every kind of bracket to basically make function calls in c++

Here are the links to the snippets, all compile and run

Rust: https://godbolt.org/z/bM3d7bG14

OCaml: https://godbolt.org/z/17oMv83zx

C++: https://godbolt.org/z/9Y3WfoE1W

you are viewing a single comment's thread
view the rest of the comments
[-] Kwdg@discuss.tchncs.de 7 points 1 week ago

You can overload the indexing operazor "[]" (std::vector does this for example), and since c++23 this operator can have more than one argument.

The last one is a constructor call with an overloaded conversion operator. The {} syntax is possible since c++11 I think. The conversion operator was already available before that

[-] xthexder@l.sw0.com 2 points 1 week ago

Ah, that's why... I didn't think multiple arguments to operator[] was valid, but my brain is still catching up to C++20 features.

this post was submitted on 30 Oct 2026
253 points (98.1% liked)

Programmer Humor

33999 readers
183 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 3 years ago
MODERATORS