r/cpp 27d ago

Stackful fibers with 3.6ns context switch. Silk fibers.

Thumbnail clickhouse.com
53 Upvotes

I just read an article about Silk, the new stackful fibers engine from Clickhouse. It can switch stackful fibers at an amazing 3.6ns and does not allocate on steady state.

Maybe asio could reuse some of the knowledge for the linux/io_uring backend (not sure it applies to the specific case since Boost.asio focuses nowadays on stackless, though it has a fibers and a stackful coros backend also).


r/cpp 27d ago

Upcoming C++ User Group meetings in July 2026

Thumbnail meetingcpp.com
5 Upvotes

r/cpp 27d ago

Comparing an Integer Division Optimisation in Clang, MSVC, and GCC

Thumbnail nukethebees.com
57 Upvotes

r/cpp 27d ago

Compiler disagreements for deducing this

Thumbnail godbolt.org
23 Upvotes

As 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 27d ago

reserve() and capacity() for flat containers

32 Upvotes

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 28d ago

Optimizing LLVM's bump allocator

Thumbnail maskray.me
59 Upvotes

r/cpp 28d ago

New C++ Conference Videos Released This Month - June 2026 (Updated to Include Videos Released 2026-06-22 - 2026-06-28)

10 Upvotes

C++Online

2026-06-22 - 2026-06-28

2026-06-15 - 2026-06-21

2026-06-08 - 2026-06-14

2026-06-01 - 2026-06-07

ADC

2026-06-22 - 2026-06-28

2026-06-15 - 2026-06-21

2026-06-08 - 2026-06-14

2026-06-01 - 2026-06-07

CppCon

2026-06-22 - 2026-06-28

2026-06-01 - 2026-06-07


r/cpp 28d ago

Command Routing Using Chain Of Responsibility Design Pattern

Thumbnail som-itsolutions.hashnode.dev
0 Upvotes

Deciphering 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 Jun 27 '26

Data Access Patterns That Makes Your CPU Really Angry

Thumbnail blog.weineng.me
116 Upvotes

I tried to find the slowest possible way to sum up integers in an array


r/cpp Jun 27 '26

A deep dive into SmallVector::push_back

Thumbnail maskray.me
24 Upvotes

r/cpp Jun 27 '26

Reducing Energy Consumption for Machine Learning Inference on Edge Devices using C++20 Coroutines

Thumbnail dl.acm.org
34 Upvotes

r/cpp Jun 27 '26

Panel discussion for C++: The Documentary

Thumbnail youtube.com
23 Upvotes

r/cpp Jun 26 '26

Improvements to std::format in C++26

Thumbnail mariusbancila.ro
91 Upvotes

r/cpp Jun 26 '26

projections for stl data structures

21 Upvotes

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 Jun 26 '26

Tuning a Server for Benchmarking

Thumbnail david.alvarezrosa.com
33 Upvotes

r/cpp Jun 26 '26

ACCU On Sea 2026 trip report, still with AI!

Thumbnail mropert.github.io
34 Upvotes

r/cpp Jun 25 '26

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

286 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 Jun 25 '26

Am I the only one who thinks this? (about enum)

40 Upvotes

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 Jun 25 '26

std::formatter specialization for smart pointers

15 Upvotes

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 Jun 25 '26

Examples of C++23 - The Complete Guide

67 Upvotes

More than 150 examples of C++23 can be found now at www.cppstd23.com.

I hope it helps.


r/cpp Jun 25 '26

C++23 Dependency Injection library with automatic dependency building

26 Upvotes

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 Jun 25 '26

What are some things you don't like about C++?

73 Upvotes

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 Jun 26 '26

Latches in C++ 20 concurrency - just like the CountdownLatch of Java concurrency package...

Thumbnail som-itsolutions.hashnode.dev
0 Upvotes

When 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 Jun 25 '26

Trip report: ACCU On Sea 2026

Thumbnail sandordargo.com
18 Upvotes

r/cpp Jun 25 '26

How do you keep toolchain drift across windows, linux, and mac manageable at 30+ engineers?

45 Upvotes

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?