this post was submitted on 17 Dec 2025
515 points (96.2% liked)

Programmer Humor

28424 readers
1369 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 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] fruitcantfly@programming.dev 2 points 3 weeks ago (1 children)

Amusingly, modern C++ allows you to copy the rust signature nearly 1:1:

auto getofmylawn(Lawn lawn) -> Option<Teenager> {
    return lawn.remove();
}
[–] Ephera@lemmy.ml 1 points 3 weeks ago (1 children)

Huh, did that emerge out of unrelated design decisions or did they just figure
why not both?

[–] fruitcantfly@programming.dev 2 points 3 weeks ago (1 children)

I believe that it is useful in a few places. cppreference.com mentions templates as one case:

Trailing return type, useful if the return type depends on argument names, such as template<class T, class U> auto add(T t, U u) -> decltype(t + u); or is complicated, such as in auto fpif(int)->int(*)(int)

The syntax also matches that of lambdas, though I'm not sure that adding another way of specifying regular functions actually makes the language more consistent, since most code still uses the old style.

Additionally, the scope of the return type matches the function meaning that you can do

auto my_class::my_function() -> iterator { /* code */ }

instead of

my_class::iterator my_class::my_function() { /* code */ }

which is kinda nice

[–] Ephera@lemmy.ml 1 points 3 weeks ago

Very interesting, thanks! 🙂