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
[-] Gladaed@feddit.org 16 points 1 week ago* (last edited 1 week ago)

Only one of those is a function, get it right. () Call functions <> Specialize Templates, can be used to do compile time calls to things that behave like functions. [] Accesses elements {} Calls constructors, aka functions that do the initial setup.

Overloading these to do something else gets you in the naughty corner.

Edit: the implementation of the {} fuckery is no great. Just save the sum instead of all numbers.

[-] Kwdg@discuss.tchncs.de 6 points 1 week ago

Good point regarding the {} implementation.

I disagree slightly regarding your point that these aren't function calls. Yes technically they are different things but effectively they are functions, I cann pass arguments and get a result based on some operations.

Of course not all of these can do anything but only the constexpr value is actually pretty limited. The other ones are straight up functions

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