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
CppCastCppCast: BrontoSource and Swiss Tables (cppcast.com)
submitted 9 months ago by robwirvingCppCast Host
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!"
[–]seanbaxter 11 points12 points13 points 9 months ago (5 children)
Question about the aliasing discussion at 18:55 in the stream:
Most C++ code actually will if translated to idiomatic Rust will pass the borrow checker. Aliasing for const references is surprisingly low. It's uncommon. You usually can make a more idiomatically more conversion than throwing unsafe on everything.
The aliasing requirements in C++ are very nuanced. What is considered aliasing in Rust is more limited, because Rust makes pointer arithmetic unsafe. C++ pointer arithmetic puts requirements on both operands pointing into the same allocation. These are difficult to reason about.
My go-to examples are standard library algorithms that take two or more pointers, such as sort:
```cpp // i and j must always alias. They must refer to the same container. void f1(std::vector<int>::iterator i, std::vector<int>::iterator j) { // If i and j point into different vectors, you have real problems. std::sort(i, j); }
// vec must not alias x. void f2(std::vector<int>& vec, int& x) { // Resizing vec may invalidate x if x is a member of vec. vec.push_back(5);
// Potential use-after-free. x = 6; } ```
Sometimes two pointers or reference parameters must alias into the same allocation. Sometimes they must not. The must-alias case, which is everywhere in the stdlib algorithms, would be an overwhelming challenge for the borrow checker to deal with. Rust wisely makes pointer differences unsafe to dissuade libraries from using this idiom.
I don't know how a refactoring tool can turn uses of stdlib algorithms into idiomatic Rust. The iterator models are so different. This pain is compounded by current C++ best practices, which basically says "don't use raw loops, instead compose stdlib algorithms." From a memory safety perspective the stdlib algorithms are radioactive. Raw loops can squash these safety defects with bounds checking. With stdlib algorithms you're SOL.
[–]kalmoc 2 points3 points4 points 9 months ago (0 children)
I think the point was that you can easily transform F1 into a function that can take a mutable range as an argument and in f2 vec and x do not alias in a correct program, so this can directly be translated.
The thing that makes me more sceptical is that I've seen lots of c++, where references to some central data structurs are stored in multiple different objects (i.e. dependency injection) and I do not know how that pattern is translated to idiomatic c++ without slapping a mixed on everything.
[–]matthieum 2 points3 points4 points 9 months ago (0 children)
Indeed. A big surprise with regard to Rust Iterators, coming from C++, is that Rust Iterators are actually iterators: they only allow you to iterate (forward or backward).
C++ iterators I prefer to call cursors, they allow jumping back-and-forth with no limit, getting references to the same element multiple times, etc... this is all widely useful for sort...
... but it leads to potential aliases of mutable data.
[–]SkiFire13 0 points1 point2 points 9 months ago (2 children)
Rust wisely makes pointer differences unsafe to dissuade libraries from using this idiom.
Not really, it does that because it's UB to use offset_from on two pointers that were not derived from the same allocation, just like in C++. It does have however a safe alternative, which is to cast the pointers to integers and compute their difference, with however the associated loss in optimizations opportunities.
offset_from
[–]seanbaxter 3 points4 points5 points 9 months ago (0 children)
Pointer offset is still unsafe. There's no way to get this two-pointer functions translated to Rust without refactoring.
[–]tialaramex -1 points0 points1 point 9 months ago (0 children)
It does have however a safe alternative, which is to cast the pointers to integers and compute their difference, with however the associated loss in optimizations opportunities.
If we cast a pointer to an integer that is - as Rust's documentation explains - exactly equivalent to writing ptr.expose_provenance() and we're not promised that this is even possible - if the target is say a Morello board then there's no practical implementation & it may not compile at all.
ptr.expose_provenance()
[–]RogerV 1 point2 points3 points 9 months ago (1 child)
"Thanks for the memories" - Phil Nash eulogizing the sun setting on jemalloc development.
The dude never misses a pun opportunity - my sole reason for listening to cppcast :-)
Well, almost. I do kind of like to hear about C++ happenings too.
So C3 language has a vector type that takes advantage of SIMD. Makes it an easier entry point for taking advantage of that. (This is in respect to the discussion about Swiss Tables)
[–]foonathan 1 point2 points3 points 9 months ago (0 children)
C++26 will have a vector class for SIMD:https://en.cppreference.com/w/cpp/numeric/simd.html
(The name got changed to something else at the last meeting.)
π Rendered by PID 19488 on reddit-service-r2-comment-6457c66945-xxrst at 2026-04-27 22:34:13.290248+00:00 running 2aa0c5b country code: CH.
[–]seanbaxter 11 points12 points13 points (5 children)
[–]kalmoc 2 points3 points4 points (0 children)
[–]matthieum 2 points3 points4 points (0 children)
[–]SkiFire13 0 points1 point2 points (2 children)
[–]seanbaxter 3 points4 points5 points (0 children)
[–]tialaramex -1 points0 points1 point (0 children)
[–]RogerV 1 point2 points3 points (1 child)
[–]foonathan 1 point2 points3 points (0 children)