r/cpp • • May 31 '26

StockholmCpp 0x3E: Intro, Info, and The Quiz

Thumbnail youtu.be
4 Upvotes

The intro of the most recent StockholmCpp Meetup, with the host presentation, some info, and a C++ quiz nobody could solve. Would you have had the answer?


r/cpp • • May 30 '26

Upcoming C++ User Group meetings in June 2026

Thumbnail meetingcpp.com
21 Upvotes

r/cpp • • May 30 '26

Status of making "reference types" 1st class citizens

12 Upvotes

Hi,

I observe more and more types with "reference-like" semantics are being added to the standard. Starting from string_view (and our old friends bitset::reference and vector<bool>::reference), we've got optional<T&> and function_ref. span and mdspan are also to an extent a reference-like type, though it can be argued that they are more of pointer-like types.

I've long hated these reference-like, or so-called "proxy" types because they are all broken, in the sense that they behave very differently from the native references. The language simply disallows a "proper" reference-like type to be written. There are two reasons I know of why this is impossible (there are maybe more):

  1. Native references get lifetime-extended, but never with proxies.
  2. It is impossible to make a proxy type to behave in the same way as the native references in the context of type deduction.

There are certain situations where these result in inconvenience and/or lifetime bugs.

  • For instance, the user of a function in a library must know if the return type is reference-like or value-like. Some may argue the user must know the exact return type anyway, but there are many legitimate situations where that is not the case. Most notable is the famous expression templates technique. Since avoiding unnecessary temporaries is why this technique is used in the first place, return types are naturally "opaque/hidden" reference-like types. The consequence is that the user must know what is the correct corresponding value-like type and must not use auto to initialize a variable from these functions/operators returning expression templates.

  • Similar fiasco happens in general for type-erasure. Basically, if you want to make your type-erased type to follow the proper value-semantics, you have to either create a separate pairing type with reference-semantics (like function_ref) or just accept unnecessary allocations from happening all the time when a function expecting type-erased arguments got called with non-erased types (which is one of the main motivation behind string_view). Now, when you have a value-type/reference-type pair (or a triple or quadruple or maybe more to include const references and rvalue references), a similar problem arises with auto. The user of an API must know if the function they are calling is returning a complete object (aka value type) or a reference to a cached result stored inside a class, if they want to avoid unnecessary allocation. Ideally, the user would just use auto if they want a copy, or to use auto const& or auto&& if they just want to refer to it transiently and then discard. That simple rule very easily breaks down when type-erasure is involved.

  • These are especially problematic in the context of generic code. Now quite often it's not only hard but also simply impossible to know this distinction of value/reference types. The usual expectation is that we get a copy if we use T and a reference if we use T&/T const&/T&&, but that (otherwise perfectly reasonable) assumption easily breaks down when proxies are involved.

As reference-like types are being increasingly common, I am wondering what is the status of any attempts for making them true 1st class citizen. Does anyone have any idea?


r/cpp • • May 30 '26

Better C++ Meetup preview on SwedenCpp , shows now online, hybrid or in person

Thumbnail swedencpp.se
16 Upvotes

The collected upcoming C++ Meetups around the world pages shows now better info if an event can be accessed online (online - hybrid) by showing visual markers

Plenty of events these days to join online!

Hope you find that useful


r/cpp • • May 30 '26

ARB v1.0: A C++23 Articulated Rigid-Body Dynamics Library for Computer Graphics

11 Upvotes

Hi r/cpp,

I’ve just released v1.0 of ARB, a modern, lightweight, header-only C++23 library for articulated rigid-body dynamics aimed primarily at computer graphics and robotics applications.

The library is intended to provide a clean and simple tool for prototyping and rapid development of rigid-body dynamics applications without the complexity and overhead of the larger physics engines  out there.

ARB is based on a differentiable spatial algebra which is used to implement  the articulated body algorithms ABA and RNEA.  ARB supports end-to-end differentiation which enables advanced techniques such as system identification, gradient based optimisation, and machine learning. The lib also  provides collision detection/resolution using GJK/EPA, and has URDF support for model import/export.

My main interest here is in getting some feedback from C++ developers  about ARB syntax and API design. 

Is it easy to use? Are there any features you think are missing? I've used C++23 - should I use C++20?

Available here: ARB


r/cpp • • May 30 '26

Reimplementation of Toyota MVCI32 in C++ as OpenMVCI

Thumbnail github.com
17 Upvotes

Finally open sourced our reimplementation of Toyota's MVCI32 driver for communication with vehicles that support J2534 protocol, this is a drop in replacement implementing it's original API. Check it out please, if you are interested please consider contributing!


r/cpp • • May 30 '26

miniaudio compile times

12 Upvotes

i found this library called miniaudio, however instead of having precompiled dll files, its just the header and then the c file that really only includes the header, the header file has all of the definitions and declarations of everything in the library, it makes the compile times take a lot of time, can i compile the header file to a dll the c file is literally just:

#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio/miniaudio.h"

and the header file is like 4 megabytes

edit: nvm i just had to precompile the miniaudio.c file with -c first and it has a shorter compile time


r/cpp • • May 29 '26

How ref qualifiers led to deducing this

Thumbnail meetingcpp.com
27 Upvotes

r/cpp • • May 29 '26

Why are C++ keywords so heavily dependent on context???

67 Upvotes

Like what do you mean inline can also be used to declare "global" variables!? I would happily accept a different keyword, inline just makes no sense here... even static would have been understandable but instead it creates private instances in each translation unit T_T


r/cpp • • May 28 '26

The C++ Standard Library Has Been Walking Itself Back for Fifteen Years

Thumbnail hftuniversity.com
98 Upvotes

r/cpp • • May 28 '26

Do You Really Need to Know All of C++?

Thumbnail youtube.com
88 Upvotes

r/cpp • • May 28 '26

VSCode extension that integrates cppreference docs into editor/LSP

Thumbnail marketplace.visualstudio.com
132 Upvotes

r/cpp • • May 28 '26

YCETL: a compile time STL like template library to generate data structures that can be used at runtimes

25 Upvotes

I posted this days ago but the 'automated admins took it down saying was generated by AI' as the formulation was maybe too academic. Trying now with other words.
Short storry: I wanted to generated python glue code for webgpu based on webgpu header. After exploring libclang and generating correct results, I wanted something more generic, more 'built in into C++'. At the beginning I thought will be easy with constexpr compile time tricks, but turned out the compile time 'runtime' is very restrictive. And I solved the challenges with ycetl. https://github.com/zokrezyl/ycetl

This is not a toy project, it is work of couple of months, fight with windmills of compile time runtime. If you see issues that can make it production ready, please share.


r/cpp • • May 28 '26

Let the Compiler Check Your Units -- Wu Yongwei (ACCU Overload)

Thumbnail accu.org
23 Upvotes

r/cpp • • May 27 '26

Lessons I’ve learned from benchmarking lock free queues

Thumbnail open.substack.com
84 Upvotes

Hey all, I’ve started writing about systems related topics, and as a first article I wanted to understand the tradeoffs of adopting lock free data structures. Turns out it’s hard to find an audience that’d be interested in this kind of topic, so I figured people here might be the best fit. Let me know what you think about the article! Would love to hear your thoughts


r/cpp • • May 27 '26

C++26: Ordering of constraints involving fold expressions

Thumbnail sandordargo.com
35 Upvotes

r/cpp • • May 27 '26

Accelerating copy_if using SIMD

Thumbnail loonatick-src.github.io
45 Upvotes

r/cpp • • May 26 '26

How an MS-DOS picklist problem in 1991 became std::bitset -- by the author who proposed it

89 Upvotes

I served on the original ISO C++ Standards Committee (J16) and proposed std::bitset. I recently wrote up the story of how it came to be -- starting from a memory-constrained MS-DOS application, through the early days of templates, and into C++98.

I also touch on the parallel story of bitstring, which became vector<bool> and eventually boost::dynamic_bitset.

https://freshsources.com/blog/files/0efc66caabe2cb443a6acae6aca0f707-0.html


r/cpp • • May 26 '26

What Happens When You Build a Chat Server on One Thread?

Thumbnail anarthal.github.io
73 Upvotes

Rubén Pérez, author of Boost.MySQL and co-maintainer of Boost.Redis, built a group chat server to show how Boost libraries work together in a real application. A working server with authentication, persistent message history, real-time broadcasting, and a React frontend. Something you can fork and deploy.

The project is called BoostServerTech Chat. It runs a single C++ process that handles HTTP, WebSocket, Redis, and MySQL connections, all on one thread. This post covers why that design holds up, what it looks like in practice, and where it comes apart.

The Stack

The server sits behind a React/Next.js frontend and talks to two backing stores: Redis for chat messages and sessions (stored as streams), and MySQL for user accounts. The C++ process does everything else: serves the static frontend files, exposes a REST API for login and account creation, and upgrades HTTP connections to WebSocket for real-time messaging.

HTTP handles requests without tight latency requirements, like account creation and authentication. Messages go over WebSocket to keep latency low.

When a user types a message, the frontend sends it to the server over WebSocket. The server persists it to a Redis stream and broadcasts it to other connected clients.

What Coroutines Look Like Here

The server is fully asynchronous, using C++20 coroutines through Boost.Asio. If you haven't used them: you write async code that reads like synchronous code. You get the performance of asynchrony without the callback tangle.

Here is a snippet from the HTTP session handler:

// Handle a regular HTTP request by querying
// the backend databases as required
http::message_generator msg =
    co_await handle_http_request(
        parser.release(), *state
    );
// Determine if we should close the connection
bool keep_alive = msg.keep_alive();
// Send the response
co_await beast::async_write(
    stream, std::move(msg),
    asio::redirect_error(ec)
);

Full source: server/src/http_session.cpp

Don't worry about every detail here. The key point: when execution reaches co_await handle_http_request(...), the server sends a query to Redis or MySQL. The coroutine suspends until the database responds. Meanwhile, other work runs on the same thread. When the response arrives, the coroutine picks up right where it left off.

Compare this to callback-based Asio code. The same logic used to require nested lambdas, explicit state machines, and careful lifetime management. Coroutines flatten all of that into something that reads like a straight line.

One Thread, No Locks

Here is the event loop setup in main.cpp:

// The server is single-threaded, so we set the
// concurrency hint to 1
asio::io_context ctx(1);

Full source: server/src/main.cpp

One io_context, one thread calling ctx.run(). Every connection, every database call, every WebSocket frame goes through the same event loop.

The payoff: shared mutable state needs zero synchronization. The server keeps an in-memory structure tracking which clients subscribe to which chat rooms. In a multi-threaded server, every access to that structure needs a strand, and getting multi-threaded Asio right is not trivial. Here, it is just a container. No locks, no races, no ordering bugs that surface under load at 2 AM.

This works because all I/O is asynchronous. A MySQL query does not block the thread. It yields, other coroutines run, and when the response arrives, the original coroutine resumes.

How Services Compose

All services live in a shared_state object passed to every session:

class shared_state
{
    struct
    {
        std::string doc_root_;
        std::unique_ptr<redis_client> redis_;
        std::unique_ptr<mysql_client> mysql_;
        std::unique_ptr<cookie_auth_service> cookie_auth_;
        std::unique_ptr<pubsub_service> pubsub_;
    } impl_;
};

Full source: server/include/shared_state.hpp

Each service is an interface with an async implementation behind it, which keeps compilation fast. The Redis client holds a single persistent connection, as the Boost.Redis docs recommend. The MySQL client uses a connection pool. The pub/sub service is an in-memory container built on Boost.MultiIndex. They all share the same io_context, cooperating on one thread with no explicit coordination.

Where This Breaks Down

The obvious limitation: one CPU core. For a chat server, that is fine. The thread spends nearly all its time waiting on network I/O. But CPU-intensive work per request (image processing, compression, heavy serialization) would block every other connection.

The subtler limitation: horizontal scaling. The pub/sub state lives in memory, so you cannot run two server instances behind a load balancer and expect messages to reach all clients. Rubén tracks this as a known next step: replacing the in-memory pub/sub with Redis channels or XREAD groups so multiple instances can share broadcast state.

Then there is the middle ground: would an io_context backed by a small thread pool with strands give meaningfully better throughput on a single machine? That is tracked as issue #25, with measurements still pending.

For anyone curious about where async C++ server design is heading more broadly, the Corosio project explores similar coroutine patterns in a different context.

The Full Picture

The entire server is around 3,000 lines of C++. It composes key Boost libraries (Asio, Beast, Redis, MySQL, JSON, Describe, MultiIndex, URL, and Test) into an application you can fork, build with CMake, and deploy in Docker. No framework, no abstraction layer hiding the details. Every layer is in the source.

The BoostServerTech Chat repo has the full code, build instructions, and architecture docs. Rubén will be in the comments.

A question worth discussing: for I/O-bound services like this, is there a real-world case where a multi-threaded io_context with strands earns its complexity? Or is single-threaded the right default until measurements say otherwise?


r/cpp • • May 26 '26

[std-proposals] Benchmarking using the standard library as a module

Thumbnail lists.isocpp.org
27 Upvotes

Some interesting benchmarks that were posted on the [std-proposals] mailing list.

The link to the entry in the mailing list archive of [std-proposals]:
https://lists.isocpp.org/std-proposals/2026/05/18441.php

For comparison:

For our modularized Windows app1, we see a reduction in build time for a full build from ~3 to ~2 minutes due to using "import std"2.

1Using the MSVC compiler with MSBuild. We currently have 1148 C++ source files, 558 containing "export module". We have 4223 imports, 357 of these are "import std".

2A while ago (~2 months), I made an experimental branch in our (closed) source code repository, which replaces every single "import std" with the minimally required #includes of the standard library headers. That was done in our fully modularized code base.


r/cpp • • May 25 '26

undercurrent: A proof-of-concept library to fix range adaptor inefficiencies

48 Upvotes

Hi, I'm a hobbyist programmer and I recently came across Barry Revzin's blog post about inefficiencies in the C++ ranges library when filter or reverse is mixed into an adaptor chain. I wanted to see if I could do something about it, and after some experimentation I ended up with this library: undercurrent.

The core idea is a customization point object uc::advance_while, which descends the iterator hierarchy recursively rather than operating at the top level. This allows algorithms to do their work at the lowest iterator level, avoiding redundant predicate evaluations.

I observed a significant speed improvement with an adapter chain like take_while | transform | filter | reverse. On Clang 22 + libc++, I'm seeing roughly 16x speedup over std::ranges. Though MSVC shows a smaller improvement (~2x). Currently supports a minimal set of adaptors and algorithms. GCC is not yet working, likely due to module-related issues.

I'd love to hear your feedback, thoughts, or any edge cases I should consider!

GitHub: https://github.com/atstana/undercurrent

Barry Revzin's blog: https://brevzin.github.io/c++/2025/04/03/token-sequence-for/


r/cpp • • May 25 '26

New C++ Conference Videos Released This Month - May 2026 (Updated To Include Videos Released 2026-05-11 - 2026-05-17)

22 Upvotes

CppCon

2026-05-18 - 2026-05-24

2026-05-11 - 2026-05-17

2026-05-04 - 2026-05-10

2026-04-27 - 2026-05-03

C++Online

2026-05-18 - 2026-05-24

2026-05-11 - 2026-05-17

2026-05-04 - 2026-05-10

2026-04-27 - 2026-05-03

Audio Developer Conference

2026-05-18 - 2026-05-24

  • Real-Time EEG for Adaptive Music in Games and VR - Marta Rossi - https://youtu.be/4kNs7cfXNgY
  • Embedded Musical Signal Processing with Csound 7 - From Microcontrollers to FPGAs - Aman Jagwani - https://youtu.be/zK0-NVkJd7E
  • Should Audio Plugins Have “Everything Everywhere All at Once”? - Exploring Modularity, Reusability, and Instrument Identity in Audio Software - Gonçalo Bernardo - https://youtu.be/XpRfkp5Swfc

2026-05-11 - 2026-05-17

2026-05-04 - 2026-05-10

  • Continuous QA Testing for Plugins Using AI and Python - Ryan Wardell - https://youtu.be/w1hLmNPxOV4
  • Using Kotlin/Compose Multiplatform to Revive a Historic Multiplayer Online Drum Machine - How To Write An Audio App That Runs Almost Everywhere - Phil Burk - https://youtu.be/8jA6Dg5iqfw
  • Converting Source Separation Models to ONNX for Real Time Usage in DJ Software - Anmol Mishra - ADC 2025 - https://youtu.be/CNs9EgMBocI

2026-04-27 - 2026-05-03


r/cpp • • May 25 '26

Building a Host-Tuned GCC to Make GCC Compile Faster

Thumbnail peter0x44.github.io
35 Upvotes

r/cpp • • May 24 '26

A brief-ish (author-consulted) guide for when to use boost::hub over plf::hive/colony, with benchmarks

63 Upvotes

std::hive/plf::hive author here, I recently found out about boost::hub via a friend, ran my own benchmarks, and contacted the author, Joaquin.

We've been talking over the past week and while we have some disagreements (more here: https://plflib.org/blog.htm#hive_vs_hub), we generally agree on the following and we've learned a bit from each other as well.

Please bear in mind that the following assumptions only apply to the current implementations of plf::hive and boost::hub, not future implementations nor other std::hive implementations.

As an example, myself and another have been working on a memory-reduced implementation of hive since august '25 (~1.2bits skipfield per element average) and we dont know what the performance results will be for that yet.

That aside, the following is true (when I say 'hive' below I mean plf::hive, and same conclusions apply for plf::colony since it's largely the same code):

* Hub is generally faster overall for smaller types, for very large types hive is typically better.

* Insert is generally faster for hub except for large types.

* Erase is faster for hub.

* Results vary a little by compiler, but in tests which measure the effect of insertion and erasure on iteration over time using 48-byte structs, hive is faster except for high churn ratios. Specifically hub tends to be better once the ratio is around or above a number of elements equal to 5% of the container size being inserted/erased for every single iteration pass over all elements. However for very small elements the ratio will likely shift downward (in hub's favour) and for very large elements the ratio will likely shift upwards (in hive's favour).

* get_iterator() performs worse when maximum block capacities are smaller, as there are more blocks to check before the pointer location is found, so hub performs much worse than hive (when default-or-larger max block sizes are used with hive) here. However the results would be the same in hive if a user were to limit the block capacities to 64-elements max themselves.

* Sorting is faster with hub except for large numbers of large types - we both need to do some work here.

* According to Joaquin's benchmarks hive seems to be a lot faster than hub for 32-bit executables, but I haven't benchmarked this.

I haven't mentioned visitation yet, but it's cool! It's a technique which can be applied to any semi-contiguous container including deques, unrolled lists like plf::list, colony, segmented vectors and potentially as a customisation point for for_each with std::hive. Basically it's iteration + pre-fetching, which only the container can do because it knows when the next block begins during iteration. It's not something you want the container to do during iteration normally because it doesn't know how the user is using the container at that point.

However, it is limiting in how you can use it - basically it's good if you want to do the same thing to a range of elements, but it doesn't work with the standard library routines such as rangesv3, because that all takes iterators. You also need to be careful with it if your code or libraries you use do pre-fetching internally.

If you can use the visit* techniques in your particular use-case may shift the balance of the above in hub's favour, except for large elements, where insertion performance can be better with hive, depending on the compiler. But I will probably implement the same techniques myself soon, for colony.

From my benchmarks across clang, gcc and msvc (https://plflib.org/benchmarks_hive_vs_hub.htm) I'll also add the following conclusions, though will likely be some variance based on CPU:

* Isolated benchmarks of insert, erase and iteration, are not sufficient to measure how a hive or hive-like container will perform during iteration over time, as erasures and reserved blocks stack up, because handling of the latter differs between containers. The proof for this can be seen in my msvc results, which have worse hive insertion, erasure and post-erasure iteration performance for the 48-byte ("small struct") isolated benchmarks than hub, but are still faster than hub in the general use (unordered modification) tests, which also store 48-byte structs and perform insertion, erasure and iteration in the same container instance over time. Only at the highest insert/erase-to-iteration ratio (10% of container size inserted/erased per-iteration) does hub perform better. This is not an anomoly; the same pattern is visible in clang and gcc, where isolated benchmarks of insert/erase are slower in hive with post-erasure iteration only 1% faster than hub, but hive is still 8% faster for all the lower churn ratios in the unordered modification benchmarks.

* Insert is slower on average for hive under msvc except for large types, slower for clang except for large types, and slower for gcc except for large numbers of large types.

* Iteration is generally faster across compilers for hive, however it is slower for 64-bit types under clang and small structs under msvc, and there is variation based on the number of elements.

* Memory use of hub varies between 96% and 50% of the usage of hive (but only for current implementation obviously).

The main thing to take away from all this is do your own benchmarks for your own use-case. You can use the guidelines above, but results may be very different on, say, a snapdragon processor. Also as mentioned, not all scenarios suit visitation. Always good to see new variations and experiments coming out! :)


r/cpp • • May 25 '26

Optimizing a real-time C++17 terminal audio visualizer, what am I missing?

19 Upvotes

I've been building spectrum, a terminal audio visualizer that hooks into WASAPI and runs FFT analysis via FFTW3. Took heavy inspiration from Winamp's spectral analyzer for the peak physics and decay behavior.

Current pipeline:
- 2400-sample Hann-windowed FFT with 95% window overlap (120-sample hop at 48kHz)
- Producer-consumer architecture, mutex-guarded shared buffers between capture and render thread
- AGC with rolling normalization + gamma contrast for dynamic range
- Logarithmic frequency binning (20Hz–16kHz) with perceptual tilt

It runs at 60 FPS with <5% CPU.

What would you optimize next?
I'm hitting a point of diminishing returns (especially with the bar height logic, and what frequencies should and should not be displayed) and would love some architectural feedback.

Considering:
- Lock-free ring buffer to replace the mutex
- WASAPI exclusive mode for lower latency capture

GitHub: github.com/majockbim/spectrum