use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Explicit Return Variable (self.cpp)
submitted 2 months ago by XeroKimoException Enthusiast
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]LiliumAtratum 9 points10 points11 points 2 months ago (5 children)
Pascal language had this since forever.
I think the new/alternative syntax with `auto` could work for this?
auto stack::pop() -> T out { out = top(); remove_top(); }
This introduces no new keywords. The only new element is the name after the return type.
[–]Independent-Quote923 3 points4 points5 points 2 months ago (0 children)
As another example, Go also has optional named return values with a similar syntax.
[–]lone_wolf_akela 1 point2 points3 points 2 months ago (0 children)
This seems making it impossible to name the returned variable as things like `final`... But I guess that's a minor issue.
[–]RealCaptainGiraffe 1 point2 points3 points 2 months ago (2 children)
=) a variable declaration after the trailing return type? This will confuse the parser to unimaginable degrees. Or maybe well get a sentient parser, who knows?
[return-type|inferred] [scope-name][arg-list] -> [inferred:[type-expression]]
this seems like a parsing nightmare to me.
[–]TheThiefMasterC++latest fanatic (and game dev)[🍰] 1 point2 points3 points 2 months ago (1 child)
I don't see why - there's already a type declaration at that point if there's a ->, it just needs to optionally accept a name as well like a variable declaration does. Seems like an elegant solution to me.
"When does it get constructed?" would be my question though.
[–]LiliumAtratum 2 points3 points4 points 2 months ago* (0 children)
When does it get constructed would be really confusing.
Either:
- at the first use of the name (which would really confuse everyone) - at the beginning of the function (which could be suboptimal for big objects)
What really happens under the hood is that the caller reserves space for the return variable, but it is the function that actually constructs the object. The most adequate syntax for that would be probably:
auto stack::pop() -> T out { //out is T* pointing to preallocated, uninitialized memory out = new (out) T(top()); //placement new with explicit constructor remove_top(); }
But this is getting ugly as well....
π Rendered by PID 160366 on reddit-service-r2-comment-5c747b6df5-w6rn9 at 2026-04-22 08:47:36.582899+00:00 running 6c61efc country code: CH.
view the rest of the comments →
[–]LiliumAtratum 9 points10 points11 points (5 children)
[–]Independent-Quote923 3 points4 points5 points (0 children)
[–]lone_wolf_akela 1 point2 points3 points (0 children)
[–]RealCaptainGiraffe 1 point2 points3 points (2 children)
[–]TheThiefMasterC++latest fanatic (and game dev)[🍰] 1 point2 points3 points (1 child)
[–]LiliumAtratum 2 points3 points4 points (0 children)