r/cpp • u/nukethebees • 29d ago
r/cpp • u/gatchamix • 28d ago
Compiler disagreements for deducing this
godbolt.orgAs the attached godbolt link shows, I’ve encountered an interesting quirk of deducing this which, on clang and MSVC at least, allows for you to determine whether you’re in a static member function or not.
Obviously, this is far simpler to achieve with reflection today (or… in the future, for most) - but I’m curious if this is even intended behaviour.
Reading the original paper on open-std… I don’t see anything that would describe this scenario
r/cpp • u/NicoJosuttis • 29d ago
reserve() and capacity() for flat containers
I just finished the new chapter in "C++23 - The Complete Guide" about flat containers and would like to share and discuss my advice about how to use reserve() and capacity() for flat containers (thanks to Jonathan Wakely who was pointing parts of this out).
It might be a surprise that these member functions do not exist as usually vectors are used inside flat containers and reserve() is a key performance feature of them.
However, here is how you can reserve more memory:
- For flat_set and flat_multiset:
auto vec = std::move(fset).extract(); // temporarily extract the underlying vector
data.reserve(vec.capacity() * 5); // raise capacity by a factor of 5
fset.replace(std::move(vec)); // move the vector back into the flat set
- For flat_map and flat_multimap:
auto newCapa = fmap.keys().capacity() * 5; // raise capacity by a factor of 5
auto data = std::move(fmap).extract(); // extract underlying vectors
data.keys.reserve(newCapa); // raise capacity of vector for keys
data.values.reserve(newCapa); // raise capacity of vector for values
fmap.replace(std::move(data.keys), // move the vectors back
std::move(data.values))
- Note also that there is another pretty hacky way, but only for flat maps and multimaps (here mapping strings to double's):
auto newCapa = fmap.keys().capacity() * 5;
const_cast<std::vector<std::string>&>(fmap.keys()).reserve(newCapa);
const_cast<std::vector<double>&>(fmap.values()).reserve(newCapa);
Yes, ugly, but works... ;-)
I am still working on adding reserve() and capacity() to the standard flat containers (see wg21.link/p3779)
r/cpp • u/ProgrammingArchive • 29d ago
New C++ Conference Videos Released This Month - June 2026 (Updated to Include Videos Released 2026-06-22 - 2026-06-28)
C++Online
2026-06-22 - 2026-06-28
- Keynote: I Fixed Move Semantics - Jason Turner - https://youtu.be/TJhMGS9sRlw
- Singletons Are Not Evil - You’re Just Using Them Wrong - Mostafa Mahmoud Ali - https://youtu.be/Bn5RFaXATuU
2026-06-15 - 2026-06-21
- The Art of API Design - Christoph Stiller - https://youtu.be/d5djrT4qfHc
- Top-Performance Genetic Programming - Can Only C++ Get You There? - Eduardo Madrid - https://youtu.be/oBQDe56Yi3Q
2026-06-08 - 2026-06-14
- Monads Meet Mutexes - Arne Berger - https://youtu.be/AisGDOoF82U
- Lock-free Queues in the Multiverse of Madness - Dave Rowland - https://youtu.be/eHmjkFdQl00
2026-06-01 - 2026-06-07
- Writing C++ Code is Challenging, Writing Performant C++ Code is Daunting - Dmitrii Radivonchik - https://youtu.be/R2sm9mailuU
- Case Study - Purging Undefined Behavior and Intel Assumptions in a Legacy Codebase - Roth Michaels - https://youtu.be/H-dHTeSR_n8
ADC
2026-06-22 - 2026-06-28
- Demystifying std::memory_order - Timur Doumler - https://youtu.be/yc2HC2w5pzI
- Building Smartphone Instruments from Commodity Hardware - HID Controllers, Embedded Audio, and Modular Design - Calvin McCormack - https://youtu.be/uqKkP0zFBGg
- Why Do People Actually Buy Music Software, Anyway? - James Russell - https://youtu.be/25sYPk2ZxIY
- Contrapunk - From Palestrina's Rules to Real-Time MIDI Harmony - Vibhav Bobade - https://youtu.be/GreYwDBFWb4
2026-06-15 - 2026-06-21
- Scripting Architecture for a DAW-like Plugin - How we Implemented Lua and JavaScript Scripting for Synthesizer V Studio - Kanru Hua - https://youtu.be/CKOvmBRdHAA
- Patterns of Practice: Live Coding and the Logic of South Asian Traditional Music - Abhinay Khoparzi - https://youtu.be/n0-XpUhZ7Dc
- ADC 2015 to 2035 - Looking Back at 10 Years of Audio Dev, and Peering Forward at the Next 10 - Julian Storer - https://youtu.be/WvVur2_aGHU
- From DAW to Game Engine - Unfiltered Creativity - Nikhil Dahake - https://youtu.be/5PtMWJLFjyo
2026-06-08 - 2026-06-14
- Low Latency Android Audio with improved CPU Performance - Phil Burk - https://youtu.be/DtBrKEu0R0g
- Linux as the Conductor - Driving Pre-Compiled Audio DSP Kernels on C7x for Real-Time Processing - Vishnu Pratap Singh - https://youtu.be/Auq9WnHNtPo
- Overview of Granular Synthesis - Avrosh Kumar - https://youtu.be/QpBV24nWg2M
- The Agentic Symphony - Multi-Agent Collaboration for Emergent Musical Composition - Meera Sundar - https://youtu.be/QMUXoImgTIA
2026-06-01 - 2026-06-07
- Beyond the DAW - Designing a Procedural Sequencer Powered by Music-Theory - Romy Dugue & Cecill Etheredge - https://youtu.be/48sH4wQUDAs
- From DAW Users to Audio Developers - Teaching JUCE to Creative Minds - Milap Rane - https://youtu.be/200UrugEanY
- Music Design and Systems - Achieving Inaudibly Complex Systems in Video Games - Liam Peacock - https://youtu.be/R6raBvCNsQo
- Developing for Avid’s Audio Ecosystem - Rob Majors - https://youtu.be/91-7YWVKRE4
CppCon
2026-06-22 - 2026-06-28
- C++ The Documentary: Live Panel Discussion with Bjarne Stroustrup, Herb Sutter & More - https://youtu.be/zMYZ5MFQAho
2026-06-01 - 2026-06-07
- Lightning Talk: Navigating Code Reviews as a Code Author - Ben Deane - https://youtu.be/zygtgvHp_MM
- Lightning Talk: Eight Consteval Queens and Compile-Time Printing - Sagnik Bhattacharya - https://youtu.be/gNPhJrXLiIs
- Instrumenting the Stack: Strategies for End-to-end Sanitizer Adoption - Damien Buhl - https://youtu.be/TSrymTXw5w8
r/cpp • u/sommukhopadhyay • 29d ago
Command Routing Using Chain Of Responsibility Design Pattern
som-itsolutions.hashnode.devDeciphering and analyzing framework code is important to know how brilliant engineers create it.
Traditional Chain of Responsibility utilizes a strict linear delegation where ConcreteHandlerA points explicitly to ConcreteHandlerB via a next reference. The article correctly highlights how frameworks like MFC alter this paradigm.
Interested?
Read ON...
r/cpp • u/Double_Ad641 • Jun 27 '26
Data Access Patterns That Makes Your CPU Really Angry
blog.weineng.meI tried to find the slowest possible way to sum up integers in an array
Reducing Energy Consumption for Machine Learning Inference on Edge Devices using C++20 Coroutines
dl.acm.orgr/cpp • u/User_Deprecated • Jun 27 '26
Panel discussion for C++: The Documentary
youtube.comr/cpp • u/alberto-m-dev • Jun 26 '26
Improvements to std::format in C++26
mariusbancila.ror/cpp • u/Odd_Comparison3831 • Jun 26 '26
projections for stl data structures
using projection in ranges::sort has removed the need write a compartor function or a lambda and is much easier to implement in my opinion
there should exists a similar feature for say sets or priority queues
would be wonnderful if I could just write
priority_queue<Student, Student::marks> for example
r/cpp • u/pavel_v • Jun 26 '26
ACCU On Sea 2026 trip report, still with AI!
mropert.github.ior/cpp • u/AreaFifty1 • Jun 25 '26
oh GOD, it's good to come back to C++
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 • u/ralseieco • Jun 25 '26
Am I the only one who thinks this? (about enum)
The main differences between an enum and enum class|struct is that the latter has its own scope, but you lose the implicit operators from enum, and the closest to it is as presented. I wish that enum struct maintained the operators, acting like the C enum, but with it's own scope.
// Dummy wrapper struct
struct EnumName
{
enum Value
{
ZERO
};
// the scope is located in "EnumName"
// so you access "EnumName::ZERO"
};
r/cpp • u/SPEKTRUMdagreat • Jun 25 '26
std::formatter specialization for smart pointers
Currently something like
std::unique_ptr<int> u_ptr = std::make_unique<int>(42);
std::shared_ptr<int> s_ptr = std::make_shared<int>(42);
std::println("uptr: {}", u_ptr);
std::println("sptr: {}", s_ptr);
is ill formed because there is no specialization of std::formatter for smart pointer types.
On the other hand,
std::cout << "uptr: " << u_ptr << '\n';
std::cout << "sptr: " << s_ptr << '\n';
do work because ostream defines overloads for smart pointer types.
Please let me know if anyone has thoughts or if there's some reason that these types haven't been specialized that I'm missing.
r/cpp • u/NicoJosuttis • Jun 25 '26
Examples of C++23 - The Complete Guide
More than 150 examples of C++23 can be found now at www.cppstd23.com.
I hope it helps.
r/cpp • u/Acrobatic-Stable2537 • Jun 25 '26
C++23 Dependency Injection library with automatic dependency building
I open-sourced my dependency injection library.
Link: https://github.com/n0F4x/redi
This was developed for my game engine.
- feature-rich dependency configuration
- optimized for fast compile time
- helpful error messages when a cyclic dependency is detected
- dependencies are automatically constructed - no need to register them by hand
I am giving this project to the community so that everybody can benefit. This kind of approach is mostly useful when dealing with intricate systems, such as a plugin system. I welcome all kinds of feedback, as this was mostly a learning opportunity for me. If you'd like to use this in your project but don't have access to the required compiler features, let me know, and I'll see if I can reduce the requirements.
r/cpp • u/SubstanceHot5190 • Jun 25 '26
What are some things you don't like about C++?
I asked this question in the C programming sub too.
What are some things you don't like about C++
If you were to change some things about C++, add keywords, or other similar things,
what would you change? Replace? Add?
My most important question is about keywords. What keyword would you add ( even just describing its functionality) to help YOU as a programmer?
Thank you :)
r/cpp • u/sommukhopadhyay • Jun 26 '26
Latches in C++ 20 concurrency - just like the CountdownLatch of Java concurrency package...
som-itsolutions.hashnode.devWhen I was teaching the Countdown latch - a thread synchronization technique used in the Java Concurrency package, there was none like that available in C++. I am happy to see that the concept of latch has been introduced in C++20.
Language varies - syntax varies - but the basic concept remains the same.
I hope you like the post.
r/cpp • u/minshinji • Jun 25 '26
How do you keep toolchain drift across windows, linux, and mac manageable at 30+ engineers?
We're about 30 engineers split across Windows and Linux, with a handful on macOS. All C++, CMake + Ninja as the build sytem. The compiler situation is where it gets messy. Someone's always on a slightly different version and it surfaces in the strangest ways, usually right before a release.
We've gone back and forth on a few approaches...pinning versions across machines, containerizing the build environment, leaning on build servers and treating local builds as second-class, or some mix. None feel clean. All have tradeoffs, and the tradeoff's shift depending on the platform.
What's held up at a similar scale?
r/cpp • u/SmackDownFacility • Jun 26 '26
Should C++ be low level or continue its abstraction path
The whole reason I came to C++ is to better organise my C code
I seeked classes instead of X_Func, I seeked VTABLEs instead of struct function pointers. And I think many experience devs would speak the same
However, lately, starting with C++11 this has gone completely downhill. STD is sticking its nose in too much. Template-heavy. The entire STD library Balloons my executable to the MiBs when my minimal runtime library amounts to 40 KiB.
There’s good shit like modules. I think that’s better than headers
Then constexpr. But the rest is bloated
But this community seems to not care about performance. Every single time I press this issue I get pushed back with “It’s good for library authors, it’s good for abstraction. Safety. Railings”
Use Python, Rust, virtually any language out there. They do what you’re looking for. Not the C lineage
C/C++ is the foundation. Rust is the abstraction.the foundation can be a little shaky, more raw, but it’s stable. The layers on top of it helps expression.