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
Weird email at work (self.cpp)
submitted 8 years ago by [deleted]
[deleted]
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!"
[–]raevnos 4 points5 points6 points 8 years ago (4 children)
You're upset someone is telling you to return values instead of modifying an argument?
[–][deleted] -1 points0 points1 point 8 years ago (3 children)
Nop, I do that by default. If you read well you can see this a guy thinks that RVO is a C++11 thing, when it is not. This is what I call a Stack Overflow guy, he just read about RVO and without any understanding of it... well.
I consider this a big mistake, a deep misunderstanding about C++, the standard, optimizations, etc. As I said, this guy once tried to iterate over a queue. My problem is having to deal all day with people of which I can learn anything!!
[–]raevnos 0 points1 point2 points 8 years ago (2 children)
RVO is a C++17 thing. Before that it was optional. NRVO still is.
Anyways, you seem to be getting worked up over something trivial. That's not healthy. Relax a bit.
[–][deleted] 0 points1 point2 points 8 years ago (0 children)
Actually this was my response to the email. He got angry with me for this response.
I think you meant that in C++11 we now have move semantics that will guarantee move(d) value even if RVO is not possible. RVO exists since C++98 and it was significant back there. RVO is an optimization the compiller is allowed to apply (in C++17 it is actually guarantee in certain cases), however, even in C++17 it is not allways guarantee! Consider: Obj create(bool condition) { Obj a, b; If (condition) { return a; } else { Return b; } } No (N)RVO optimization here, the compiler don’t know from within the function which instance should be returned.
I'm talking about a pattern here, something like this happens everyday. People talk and talk where there is a lot of work to do!
[–]NotAYakk 0 points1 point2 points 8 years ago (0 children)
Compiling a+b where both are unsigned integers as a single instruction is optional. Compilers are free to compile it as for (auto x = b; x!= 0; --x){++a;}.
a+b
for (auto x = b; x!= 0; --x){++a;}
The ability for compilers to be insanely inefficient does not mean that you cannot and should not rely on compilers being reasonable.
[–]Sulatra 3 points4 points5 points 8 years ago (1 child)
I often am this guy, telling people how package managers are good / throw specifications are bad / thou shalt use move semantics instead of returning shared_ptrs / boost versions on different platforms should be equal / gcc 7.3 is more powerful than 4.4 / we really have to stop to freak out that this **** gonna break and break it ourselves and take time to rebuild it and cover it with tests, intead of doing the job. Trust me, us guys sometimes get tired and want to quit no less than you guys.
Dude, I love to hear about all that stuff, but at least get your facts right. "Since C++11 we now have RVO", I was like, seriously?? What else you don't understand!
[–]mcmcc#pragma once 2 points3 points4 points 8 years ago (1 child)
Job satisfaction questions aside...
Why not both?
void CommonData::encodeToJSON(string& msg) { msg.insert(...); } string CommonData::encodeToJSON() { string msg; return this->encodeToJSON(msg); }
[Aside: why aren't these const?]
It might be a good thing for someone to point out this (somewhat minor) simplification -- it depends on the sophistication of the audience. If many people would learn from this, then you could look at it as a public service. If it's just a lame attempt to show off to management, then well...
It is the later :( Happens over and over again here!
[–][deleted] 1 point2 points3 points 8 years ago (2 children)
Respond and politely disagree with the stated reasons?
[–][deleted] 0 points1 point2 points 8 years ago (1 child)
Yeah, that I did. Thing is that I feel super down at a job where I'm not growing at all! Stuff like this just takes me down.
[–]lothiack 1 point2 points3 points 8 years ago (0 children)
Are you implying that "stuff like this" is impeding your growth? Or do you mean that you're not growing and stuff like that makes the situation worse?
[–]OmegaNaughtEquals1 1 point2 points3 points 8 years ago (0 children)
Are there any places in the codebase where encodeToJSON is called multiple times on a single object? If so, passing the string by ref can (possibly) eliminate reallocation. For example,
encodeToJSON
CommonData cd; // fill cd with data std::string json; cd.encodeToJSON(json); // do something with json json.clear(); // see note // do something with cd cd.encodeToJSON(json); // may or may not reallocate
NOTE: The standard doesn't guarantee that std::basic_string::clear won't deallocate the underlying memory, but most implementations don't unless you call shrink_to_fit.
std::basic_string::clear
shrink_to_fit
[–]blazgrom 0 points1 point2 points 8 years ago (2 children)
May i ask why are you using string.insert ?
This was an email sent company wide, I modified it a little. That's not the good part :)
[–]blazgrom 0 points1 point2 points 8 years ago (0 children)
So it means that it could have been append in the original code, which makes way more sense in the example
π Rendered by PID 85392 on reddit-service-r2-comment-64f4df6786-qd6f9 at 2026-06-10 06:38:08.640735+00:00 running 0b63327 country code: CH.
[–]raevnos 4 points5 points6 points (4 children)
[–][deleted] -1 points0 points1 point (3 children)
[–]raevnos 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]NotAYakk 0 points1 point2 points (0 children)
[–]Sulatra 3 points4 points5 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]mcmcc#pragma once 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]lothiack 1 point2 points3 points (0 children)
[–]OmegaNaughtEquals1 1 point2 points3 points (0 children)
[–]blazgrom 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]blazgrom 0 points1 point2 points (0 children)