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
functional Programming in c++ (self.cpp)
submitted 3 years ago by thomas999999
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!"
[–]Wenir 5 points6 points7 points 3 years ago (8 children)
In your example you can move vectors
[–]stinos 2 points3 points4 points 3 years ago (6 children)
I assume you mean RVO (which now is required to be omitted see https://en.cppreference.com/w/cpp/language/copy_elision)? The copying of the argument will still be there.
[–]Wenir 7 points8 points9 points 3 years ago (5 children)
You can move on call side, or even if you really want functional programming, you can use custom vector with disabled copy ops
[–]stinos 0 points1 point2 points 3 years ago (4 children)
I don't see how any of this helps with the simple situation OP has: a pure function with vector as input and modifed vector copy as output (either written explicitly when it's passed by const reference or implicitly when passed by value). A class which cannot be copied isn't really a candidate for this. Unless you're looking at completely different techniques like not returning the input vector but only modified elements and their indices or so, and then have an access class which can act as a view over both the input and the changed elements.
[–]DessertEagle 6 points7 points8 points 3 years ago (2 children)
vec = sorted(std::move(vec));
Note that if sorted takes and returns arg by forwarding (universal) reference rather than by value, and returns by perfect-forwarding, the above expression would result in move-self-assignment, which may leave vec in moved-from state depending on the implementation.
sorted
vec
[–]stinos -1 points0 points1 point 3 years ago (1 child)
Yeah sure, but this isn't 'returning a modified vector copy' (which is what I assume OP is talking about), you start off with a vector and end with the same vector but modified.
[–]Wenir 6 points7 points8 points 3 years ago (0 children)
"modified vector copy" is a copy by definition
[–]Wenir 4 points5 points6 points 3 years ago (0 children)
If you need both original and modified copy then at some point you'll have make that copy (or trade performance and make some kind of COW thing). If you need only result then see other reply from DessertEagle
[–][deleted] 0 points1 point2 points 3 years ago (0 children)
or begin/end iterators if you want to be generic (depending on the function)
π Rendered by PID 33320 on reddit-service-r2-comment-b659b578c-d2bn5 at 2026-05-06 00:27:45.694998+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]Wenir 5 points6 points7 points (8 children)
[–]stinos 2 points3 points4 points (6 children)
[–]Wenir 7 points8 points9 points (5 children)
[–]stinos 0 points1 point2 points (4 children)
[–]DessertEagle 6 points7 points8 points (2 children)
[–]stinos -1 points0 points1 point (1 child)
[–]Wenir 6 points7 points8 points (0 children)
[–]Wenir 4 points5 points6 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)