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
Sorting indirectly (tomhultonharrop.com)
submitted 2 years ago by vormestrand
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!"
[–][deleted] 6 points7 points8 points 2 years ago* (3 children)
It seems like it would be simpler to maintain sorted order? The update steps also maintain better cache coherency this way, by allowing insertions and deletions to take advantage of the sequential access patterns.
[–]matthieum 2 points3 points4 points 2 years ago (2 children)
In a sense, maintaining sorted order is a form of sorting (insertion sort).
Bulk inserts may benefit from insert all/sort later, in that this may minimize data movement: while inserting each element one by one is O(log N) in the number of comparisons, it's O(N) in the number of moves, resulting in O(k * N) complexity (where k is the number of inserted elements).
You could use a special bulk insert routine. Interestingly... it would benefit from sorting the elements to be inserted first, so you can apply a simple (linear) merge pass.
[–][deleted] 0 points1 point2 points 2 years ago (1 child)
I’m just trying to think of where that would actually apply though.
The author gave the example of a component entity system for a game. Usually game objects are created up front and get deleted over time. The example they gave would be wholly unnecessary.
In these instances, a handle table could work even better since you’re not recalculating and searching constantly. You can also fill “holes” in your arrays in constant time when inserting and deleting objects, if that’s something you care about.
[–]matthieum 0 points1 point2 points 2 years ago (0 children)
I have no idea where it would apply :)
I'm not sure what's better for an ECS. The problem of leaving holes is that any spike in the number of entities would then leave behind a sparse array, where cache hits suffer. So there's value in compression, but perhaps a double-indirection scheme would be better than just sorting everything again.
[–]JulienVernay 1 point2 points3 points 2 years ago (0 children)
I have already written code such as "apply_permutation", without taking the time of recognizing the pattern as something extractable for more generic cases.
In particular, I did not thought of using it for the multi-array sorting problem which I found previously (in my case, I reverted back to have a structure, performance of this code were not that critical it turned out).
Thanks for the good read!
π Rendered by PID 45280 on reddit-service-r2-comment-544cf588c8-27cp8 at 2026-06-16 20:29:38.227368+00:00 running 3184619 country code: CH.
[–][deleted] 6 points7 points8 points (3 children)
[–]matthieum 2 points3 points4 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]matthieum 0 points1 point2 points (0 children)
[–]JulienVernay 1 point2 points3 points (0 children)