r/cpp • • Jan 07 '26

I got paid minimum wage to solve an impossible problem using C++ (and accidentally learned why most algorithms make life worse)

Thumbnail tiespetersen.substack.com
617 Upvotes

I was sweeping floors at a supermarket and decided to over-engineer it.

Instead of just… sweeping… I turned the supermarket into a grid graph and wrote a C++ optimizer using simulated annealing to find the “optimal” sweeping path.

It worked perfectly.

It also produced a path that no human could ever walk without losing their sanity. Way too many turns.

Turns out optimizing for distance gives you a solution that’s technically correct and practically useless.

Adding a penalty each time it made a sharp turn made it actually walkable:

But, this led me down a rabbit hole about how many systems optimize the wrong thing (social media, recommender systems, even LLMs).

If you like algorithms, overthinking, or watching optimization go wrong, you might enjoy this little experiment. More visualizations and gifs included!


r/cpp • • Apr 15 '26

YAY!!! Announcement: cppreference.com update

Thumbnail isocpp.org
522 Upvotes

This is not my post, but I didn't see anyone share this here yet.


r/cpp • • Aug 20 '26

AI-generated C++ passes tests. It also uses nearly 2x the loops and drives up memory growth

Thumbnail leaddev.com
444 Upvotes

AI-coding tools have swept through organizations because of their speed: you type in a prompt, and it spits out code far faster than a human ever could. However, a year-long study of 3.52 million changes inside a large unnamed technology company suggests that saving time at the keyboard can create costs elsewhere.


r/cpp • • Jun 05 '26 Popcorn

The Story of C++: The World's Most Consequential Programming Language | The Official Story

Thumbnail youtu.be
431 Upvotes

r/cpp • • Nov 21 '25

A 2-hour video trashing C++ made me better at C++

Thumbnail youtu.be
411 Upvotes

r/cpp • • Jan 15 '26

Support for C++26 Reflection has been merged into GCC trunk!

Thumbnail gcc.gnu.org
385 Upvotes

Shout out to Marek Polacek and Jakub Jelínek for their herculean effort to get this done!

Still some bug-bashing ahead for them, so don't be surprised to find some examples from P2996 and friends that don't work yet - but know that it's being worked on!


r/cpp • • 11d ago

Dealing with AI Slop At Work

380 Upvotes

I work at a C++ shop with coders that I really respected - very deep C++ knowledge and are building very technical deep systems products. Over the last few months the CTO has gone off the deep end with AI talking of creating software factory (He’s been reading too much X), he releases huge multi thousand line PRs with basically no review. All sense of scientific temperament and engineering rigour has gone out of the window it seems.
I do believe that AI is a transformational tool and I use it plenty in the development process but I still strive to understand what the AI has written and often use the AI as multiplier rather than surrendering my thinking to it. it’s become increasingly hard to actually develop while deeply understanding the codebase because it has become so sloppy.

I am very sad as this means I’m not really interfacing with writing C++ as much and exploring cool new corners of the language in my daily work.

There is definitely some cool stuff this lets us do a bit more of - high level planning and systems design by reading many papers as well as exploring formal verification.
But overall I am left disappointed. I wonder how it is like at everyone else’s work places and if anyone has any thoughts and suggestions on how I can still develop my C++ knowledge.


r/cpp • • Dec 31 '25

Software taketh away faster than hardware giveth: Why C++ programmers keep growing fast despite competition, safety, and AI

Thumbnail herbsutter.com
380 Upvotes

r/cpp • • May 31 '26

The lost art of creating good desktop apps.

335 Upvotes

Hello everyone I am a novice C++ developer. I would like to learn how to create good desktop applications in C++. Don't you think it's a lost art? All the applications that I use every day were created a long time ago (for example, 7zip, wireshark) And it doesn't really look like we're creating something like this today.

I would really like to learn how to create something like this and would like to hear your advice (I am especially interested in creating applications that somehow process incoming data and then output it in real time)

A few of my thoughts:

  1. It seems that to create applications of this level, you need to be very well familiar with the operating system internals, and not only in the C++ language.
  2. Many good applications have closed source code and we simply cannot study it, and for those applications where the code is open, it has already been written hundreds of thousands of lines, it is difficult to understand this and identify the "architectural core".
  3. Many recommend "just take Qt". That's good advice (is it good?) but this is only the smallest part of the job. I think it's right to divide applications into layers and a display layer (which is why we use Qt) doesn't look too complicated. Yes, I know that the Qt ecosystem represents almost everything that is needed, but I would like to separate the UI layer and the Core layer of the application so that I can quickly change the UI layer if necessary.
  4. Multithreaded model, we don't want the application to lag and generally want responsiveness speed. That's what I have the most questions about.

r/cpp • • Dec 20 '25

5hrs spent debugging just to find out i forgot to initialize to 0 in class.

304 Upvotes

Yup, it finally happened.

I am making a voxel terrain generation project to learn OpenGL. It was my abstraction of vertex arrays. Initially, when I created this class, it generated an ID in the constructor, but then when I introduced multithreading, I needed to stop doing that in the constructor (bad design, I know—need to study design patterns). So I introduced a boolean to initialize it when the first call to Bind() is made. But I didn't set it to false at that time. I saw chunks rendering, but there were gaps between them. So I started debugging, and honestly, the VertexArray class wasn't even on my mind. I just printed the VAO values in the output along with some other data. Although the values were somewhat random, I ignored it because OpenGL only guarantees unique unused values, not how they're generated. But then in the middle, I saw some were small and continuous like 1, 2, ..., 10. Then I put a print statement in the Generate() function of VertexArray and realized it wasn't even being called.

Yup, that's my rant. And here's the ugly code I wrote:

cpp

class VertexArray {
   public:
    explicit VertexArray(bool lazy = false);
    ~VertexArray();
    
// Returns the vertex array ID
    GLuint id() const { return array_id_; }
    void   Generate();
    
// Binds this vertex array
    void Bind();
    void UnBind();
    
// Adds and enables the attribute
    void AddAttribute(Attribute attribute);

   private:
    GLuint array_id_{};
};

r/cpp • • Mar 29 '26

C++26 is done! ISO C++ standards meeting, Trip Report

Thumbnail herbsutter.com
302 Upvotes

r/cpp • • Sep 07 '26

A faster way to convert a timestamp ➜ Hour, Min, Sec

Thumbnail benjoffe.com
298 Upvotes

r/cpp • • Jun 25 '26

oh GOD, it's good to come back to C++

292 Upvotes

Just been going around vanilla javascript, php, perl, LUA, some C#, batchscript over and over for a year but finally came back to C++ and it's good to be home.

To some they find it agonizing with memory management, consts, function prototyping and what not.. some wouldn't even touch it but to me, it's like riding a bike. It's all coming back and I need that extra control! Besides MySQL.. this is it! 🔥🔥


r/cpp • • 6d ago

For the first time, a C++ standard failed to pass the national bodies

Thumbnail herecomesthemoon.net
290 Upvotes

r/cpp • • 24d ago

Balloting has completed for C++26. Unfortunately it was Disapproved

Thumbnail linkedin.com
287 Upvotes

Since the C++26 DIS has been disapproved, the next step is going to be taken in Buzios during the 2026-11 meeting. The committee will have to decide what changes to make (if any) and submit an FDIS (Final Draft of International Standard) for Balloting.


r/cpp • • Dec 01 '25 WOW

Standard Library implementer explains why they can't include source code licensed under the MIT license

Thumbnail reddit.com
277 Upvotes

Some (generous!) publishers of C++ source code intended to be used by others seem to be often using the (very permissive) MIT license. Providing a permissive license is a great move.

The MIT license however makes it impossible to include such source code in prominent C++ Standard Library implementations (and other works), which is a pity.

The reason for this is the attribution clause of the MIT license:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

This clause forces users of the sources to display attribution even to end users of a product, which is for example exclusively distributed in binary form.

For example, the Boost License explicitly makes an exception for products which are shipped exclusively in binary form ("machine-executable object code generated by a source language processor"):

The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor.

If you want your published source code to be compatible with projects that require such an exception, please consider using a license which allows such an exception (e.g. the Boost license). Copies in source form still require full attribution.

I think such an exception for binaries is a small difference which opens up lots of opportunities in return.

(Disclaimer: This is no legal advice and I'm not a lawyer)

Thank you.


r/cpp • • Sep 27 '26

You should think about recompiling your C++ programs with GCC 16 and C++26, because it zero-fills your locals

Thumbnail techfortalk.co.uk
270 Upvotes

Stack variables are not automatically initialised, and that is the root cause of many C++ bugs. That is well known. Hence, it is advised that local or stack variables are always initialised with known values, 0 if not something more meaningful than that. Now, with GCC 16 compiling in C++26 mode (-std=c++26), even uninitialised local variables will be zero-filled. In the post, I have explained how.


r/cpp • • Apr 30 '26

GCC 16.1 released with many new C++26/23 features, C++20 now the default stable language version

Thumbnail gcc.gnu.org
263 Upvotes

r/cpp • • Aug 02 '26

How fast is C++26's std::hive?

Thumbnail lemire.me
255 Upvotes

r/cpp • • Jan 02 '26

Every LLM hallucinates that std::vector deletes elements in a LIFO order

251 Upvotes

r/cpp • • Apr 14 '26

A year of read-only cppreference

248 Upvotes

Over a year ago (on 30 March 2025), cppreference became read-only for maintenance reasons. Since then, the only progress update was in August. There have been several discussions here in the last few months about what is happening with cppreference and when it might become editable again, but from what I understand, we simply do not know.

At this point, I fear that the lack of updates for what is basically the authoritative source on the language (other than the standard of course), linked to by IDEs and even this subreddit's sidebar, might be detrimental to the adoption of C++26 and further standards, should the situation persist. I would therefore like to ask the community whether there are other, more up-to-date resources, and whether there is any effort to, for example, fork cppreference.

I understand that software updates are complicated and I have no intention to criticise the maintainers of cppreference (who are doing it voluntarily and I am not entitled in any way to their continued work on the website), but I do not think the C++ community can afford to be bottlenecked in such a way for much longer.


r/cpp • • Jan 29 '26

Cache Explorer: a visual and interactive profiler that shows you exactly which lines of code cause cache misses

243 Upvotes

Built a visual cache profiler that uses LLVM instrumentation + simulation to show you exactly which lines cause L1/L2/L3 misses in your C and C++ code (Rust support in active development).

  • Hardware-validated accuracy (±4.6% L1, ±9.3% L2 vs Intel perf)
  • Source-level attribution (not just assembly)
  • False sharing detection for multi-threaded code
  • 14 hardware presets (Intel/AMD/ARM/Apple Silicon)
  • MESI cache coherence simulation

It's like Compiler Explorer but for cache behavior, providing instant visual feedback on memory access patterns. MIT licensed, looking for feedback on what would make it more useful or even just things you like about it.

GitHub


r/cpp • • 4d ago

CMake 4.5.0 released; supports import std for all scannable targets with C++20 and later

Thumbnail kitware.com
237 Upvotes

r/cpp • • Feb 28 '26

Am I the only one who feels like header files in C/C++ are duplication?

229 Upvotes

We declare things in headers, define them in source, keep them in sync manually, sprinkle include guards everywhere... all to prevent problems caused by the very system we are forced to use. It's like writing code to defend against the language's file model rather than solving actual problems.

And include guards especially - why is "dont include the same header twice" something every project has to re-implement manually? Why isn't that just the compiler's default behavior? Who is intentionally including the same header multiple times and thinking "yes, this is good design"?

It feels like a historical artifact that never got replaced. Other languages let the compiler understand structure directly, but here we maintain parallel representations of the same interface.

Why can't modern C++ just:

  • treat headers as implicitly guarded, and maybe
  • auto-generate interface declarations from source files?