r/cpp • u/tcbrindle • 19d ago
r/cpp • u/victor-s8n • 20d ago
How I design C++ classes
rafb.euThis is my first ever blog-post, any feedback is welcome! ofc, no AI got used.
r/cpp • u/R3DKn16h7 • 20d ago
Pretty nasty MSVC 19.51 hash of float bug
Hash of 0.0 and -0.0 are not the same, as the condition:
_Keyval == 0.0F ? 0.0F : _Keyval
is optimized away if you compile with:
/arch:AVX2 /O2
https://godbolt.org/z/45WPzceYx
If you use Visual Studio 2022 it works fine. I'm somewhat surprised they don't have regression tests since the standard library explicitly handles this case.
So I guess, check you hash maps if you update.
r/cpp • u/Background-Error-910 • 19d ago
Maybe C++ would win if it adapted quicker?
I know that I'm oversimplifying here. The way the new C++ standard is released is pushing the language behind the others, especially those who adapt new language features quicker and favorize new modern language features.
I'm not saying that the movement towards modern C++ (whatever that might mean) is not helping. I love the fact that there are new exciting features such as reflection in the C++26 standard. Saying that however, even though the standard is supposed to have these features, the adaptibility by the compilers and the ecosystem is extremely slow.
Here we are in 2026 and MSVC as of now has zero C++26 core language features implemented. And god knows how long they will be unavailable. I feel like only now when its 2026, c++23 started to be slowly adopting, which I find sad. PS: I'm aware that GCC has mostly all features implemented, but STILL not all of them. Similar situation for Clang.
Maybe a more "aggressive" and faster release cycle would help? Also faster deprecation and language cleanup? The general push has always been towards backwards compatibility, but you can't always add new things that people want without breaking compatibility and removing deprecated features. And I think that for the language it's very important to adapt the modern programming language standards. But now I don't feel like that's happening.
Obviously there are other issues with C++, such as not having standardized package managers, linters, formatters, etc. For example, the clang-tidy formatter is abysmaly slow, and just painful to use, probably because it has to accomodate the million features the C++ language permits, and even the things that doesn't make sense no more and are just left in the language as obsolete things, ready to be removed after 20 years, which is hilarious.
Anyway, what are your thoughts on this topic?
EDIT: I agree that chosing the wording "win" is a bad wording here. The main point was to address some of the weaknesses C++ has compared to other languages/ecosystems.
Catastrophic misoptimization of byte-range equality comparison in all major C++ compilers (and Rust). Language issue or compiler issue?
Someone brought a C++ snippet that reduced to the following (std::array used instead of char* for consistency for later)
bool eq2(const std::array<char, 64>& lhs, const std::array<char, 64>& rhs) {
for (int i = 0; i < 64; ++i)
if (lhs[i] != rhs[i])
return false;
return true;
}It basically returns true iff two 64 byte memory regions are a bitwise match. You'd think this can be optimized by modern compilers flawlessly, right? Right?! And the worst thing that can happen is it doesn't get autovectorized, right? Right?!
Well, to everybody's surprise... https://godbolt.org/z/v4d8G5ovh
GCC attempts to partially conditionally vectorize but doesn't want to use unaligned loads. Moreover its vectorization is way more cumbersome than it needs to be. Then after it finds a mismatch it... reverts to the unvectorized version?! Clang and MSVC do not even attempt to vectorize it - and in a way it makes them end up better than GCC, which is wild.
Now, to try to investigate we've checked how it looks in Rust. https://godbolt.org/z/K7xE3qc94. It does what GCC does but fully vectorized.
At this point we're confused as to what the source of the problem is. Are we missing something with respect to what transformations are allowed? Is it really that much to ask from the as-if rule?
As a sanity check we use std::array's operator==. https://godbolt.org/z/xPhPYMjvz. Oh would you look at that? Now the compilers can do well (ok not you MSVC. GCC also fumbles the flag register slightly). The situation is the same in Rust - https://godbolt.org/z/3GjWorze8. Not only does it vectorize correctly but the vectorized code is better - using vpxor.
Ultimately this isn't just academical. Situations like this undermine the trust in the compiler at the most fundamental level. Not every place can use std::array, not everyone can use ranges and span yet. We could use std::equal but why does it matter so much? What if != changes to < and there's no good solution anymore? To what degree are we supposed to be paranoid about basic optimizations being done or not?
The similarity of codegen between Rust and C++ would point to it being either a compiler issue or a fundamental code correctness issue. The fact that C++ Clang differs from Rust (LLVM) would suggest it's at least partially a language issue. Why is this extremely simple code so nasty?
edit. some more [not so] fun findings https://www.reddit.com/r/cpp/comments/1xlyti8/catastrophic_misoptimization_of_byterange/19s1i09srxdaa/
r/cpp • u/ProgrammingArchive • 21d ago
New C++ Conference Videos Released This Month - November 2026
C++Day
2026-10-26 - 2026-11-01
- [C++ Day 2026] Old-School C++ for the Agentic Age: Lessons from Sane C++ (Stefano Cristiano) - https://www.youtube.com/watch?v=tAf-HsET0pE
- [C++ Day 2026] Zero-cost GIS: parsing binary formats in C++23 (Giorgio Bignotti) - https://www.youtube.com/watch?v=VHeNHf6t76Q
C++Now
2026-10-26 - 2026-11-01
- AI is Forcing us to Obey Scott Meyers - Jody Hagins - https://youtu.be/CiaZq4kCH08
- C++ Libraries - The Road Ahead - Jeffrey Garland - https://youtu.be/bNipVnNaDdk
- Lightning Talk: ?: - Jonathan Müller - https://youtu.be/TLj6NVx5xvk
ACCU
2026-10-26 - 2026-11-01
- Creating Composable Callables in Contemporary C++ - Using Senders / Receivers as a Frame Graph - Björn Fahller - https://youtu.be/A4mMO5xeQDA
- Incrementally Migrating C++ to a Memory Safe Language with Swift - Tim Condon - https://youtu.be/LMQ21X6_2FQ
- CallMeMaybe - Building Modern Runtime Reflection via C++26 - Laurie Kirk - https://youtu.be/cA0F3wRtZIU
ADC
2026-10-26 - 2026-11-01
- TX/RX Part 2 - AI Audio on the Raspberry Pi - Kieran Coulter - https://youtu.be/QSiyLDHoBpo
- JUCE in DJ Products - Current Status and Future Prospects - Masamichi Tomii, Akihito Yamada & Tetsuro Abe - https://youtu.be/VElORkcpE78
- Generative Instruments with Large Piano Models - Tomek Roszczynialski - https://youtu.be/EO-hGj8_BUY
r/cpp • u/JimmyHu1994 • 22d ago
C++20 Concept Trap of std::inserter and std::array
github.comI am trying to design a generic function template to populate both dynamic-sized containers (like std::vector<>, std::deque<>) and fixed-sized containers (std::array<>) using modern C++. It is natural to reach for a C++20 concept and if constexpr. Then, when I wrote the constraint for if constexpr statement, I found that the following design would be failed.
template<typename T>
concept naive_is_inserterable = requires(T& x)
{
std::inserter(x, std::ranges::end(x));
};The structure like:
template<std::ranges::input_range Range>
void foo(Range& container)
{
if constexpr (naive_is_inserterable<Range>)
{
// Passes std::inserter(container, ...) to an algorithm (which invokes container.insert()) for dynamic-sized containers.
}
else
{
// Fallback for fixed-size containers
}
}would fail to compile.
Only fix the concept to:
template<typename T>
concept is_inserterable =
std::ranges::range<T> and
requires(T& x, std::ranges::range_value_t<T> v)
{
x.insert(std::ranges::end(x), v);
std::inserter(x, std::ranges::end(x));
};Then use it like:
template<std::ranges::input_range Range>
void foo(Range& container)
{
if constexpr (is_inserterable<Range>)
{
// code for dynamic-sized containers.
}
else
{
// Fallback for fixed-size containers
}
}to solve the issue.
Discussion Questions
- Should C++ standard library implementations (or a future defect report) constrain
std::insert_iterator::operator=andstd::back_insert_iterator::operator=on the underlying container operations (insert,push_back), or would that break valid legacy code? - How do you prefer to structure insertion traits when writing generic functions that support both dynamic containers and
std::array?
HPX V2.0.0 released: C++20 baseline, C++20 modules, stdexec-based senders/receivers, early C++26 reflection! - The HPX Project
HPX, the C++ Standard Library for Parallelism and Concurrency, has released V2.0.0. It is the largest release in a long time: more than 830 merged pull requests from more than 90 contributors since V1.11.0.
HPX implements the C++23 Standard parallelism and concurrency facilities in full and offers the only widely available open-source implementation of C++17, C++20, and C++23 parallel algorithms - including a complete set of parallel range-based algorithms and the full integration of the algorithms with the upcoming sender and receivers interfaces.
Beyond the standard, HPX includes proposed features for upcoming C++ releases: much of the parallelism and concurrency capabilities expected in C++26, the C++ Concurrency TS, Parallelism TS V2, data-parallel algorithms, executors, senders and receivers, and more. It also extends C++ Standard APIs to distributed environments (such as compute clusters) and heterogeneous systems (such as GPUs).
Some of the changes that may interest r/cpp:
- C++20 is now the minimum, and the whole library can optionally be built and consumed as C++20 modules.
- Our own std::execution implementation is gone; senders and receivers are now based on stdexec, and a P2079 parallel scheduler runs sender work on HPX thread pools.
- Early use of C++26 reflection: types can be serialized without writing serialize() functions, and remote actions and components no longer need registration macros.
- New C++23 parallel algorithms (the fold family, find_last, iota) and many conformance fixes in the existing ones.
- Functions can carry a task size (nano_task, small_task, ...), which the parallel algorithms use to decide how to split a loop.
HPX enables an asynchronous C++ programming model that improves parallel efficiency and reduces the complexity typically associated with concurrent applications. As a newly welcomed project of the High Performance Software Foundation, HPX now benefits from vendor-neutral governance and collaboration with a broader ecosystem of high-performance computing tools, strengthening the foundation for portable, production-ready HPC software across the industry.
Release: https://github.com/TheHPXProject/hpx/releases/tag/v2.0.0
What's new: https://docs.hpx.dev/latest/html/releases/whats_new_2_0_0.html
Hans Wennborg: Windows debug info - CodeView and PDB files
youtu.beSymbolic debug info on Windows. There is no specification, very little
documentation, and the whole thing is more or less shrouded in mystery.
This talk will attempt to explain how debug info works on Windows:
CodeView, PDB files, and how it all fits together.
r/cpp • u/StudentTraditional64 • 23d ago
How do I avoid UB in contracts?
This question might be better served in /r/cpp_questions but since contracts were the reason C++26 failed the latest vote I thought posting it here might generate some useful debate.
I've been using contracts in personal projects since GCC16 was released. I've come to appreciate them both as documentation and in bug-finding. After the recent controversial vote I did have another look at them and their use in my code. Most of my contracts looks like the example in "3.5.5 Consecutive and Repeated Evaluations" of p2900:
void f(int *p)
pre( p != nullptr ) // precondition #1
pre( *p > 0 ); // precondition #2
This works as expected in enforce, quick-enforce and ignore evaluations. However if I use observe evaluation it'll crash with UB on the second precondition.
One fix is to merge the preconditions together pre( p != nullptr && *p > 0) which works in this case, but doesn't scale to for example classes where you'll have pre( p != nullptr) on the constructor and then assume it's valid for the rest of the body.
Another solution is to never use observe evaluation. This works in my applications where I control the build, but doesn't work in libraries used by others where I don't.
I wonder what my options here are?
Edit Godbolt link
r/cpp • u/meetingcpp • 23d ago
Upcoming C++ User Group meetings in November 2026
meetingcpp.comPitfalls of bit fields in C++
pvs-studio.comBit fields can help save memory in C++, but their layout and behavior depend on compiler and platform details. The article explores their pitfalls with examples of how GCC, Clang, and MSVC handle them.
C++26, WG21, and ISO's national bodies
a4z.noexcept.devSome notes for C++ users who don't follow the committee closely but want some background on the current dispute in the C++ community.
r/cpp • u/False_Actuator_6236 • 26d ago
C++ BLAS Library for bringing two worlds together I would like
I would like to discuss the need (or no-need) for a C++ interface/libary that is intended to be a - building block for high level linear algebra packages and - low-level, hardware oriented implementations of special numerical operations.
The “high-level world” …
In the C++ world, you have libraries like Eigen, Blaze, … where you can matrix operations like
C = A * B;
and regarding performance often stops here. Because some experts figured out how to implement such that it’s fast.
Or maybe there is a short discussion why you should write
C.noalias() = A * B;
in Eigen.
And that’s great. In this world you wanna build something great based on Linear Algebra operations.
The “Low-level world” …
Then there is the world of BLAS (Basic Linear Algebra Subprograms), with implementations such as Intel MKL, OpenBLAS, BLIS, or Apple Accelerate. So for some reason there is money and time involved.
They provide implementations for the matrix product that are very efficient. But maybe not that user friendly to use. For example they provide a function for the operation
C ← βC + αAB
where A, B and C are matrices. Where elements can all be float, or can be double, or can be complex-float or can be complex-double. But all of the same type.
And A and B can be either not-transposed or transposed (in the complex case actually conjugated-or-transposed).
A call to this function looks like this when you use the Fortran Interface (GEMM is short for General Matrix Matrix Product, D indicates that elements and scalars all have double precision) :
dgemm("N", "N", &m, &n, &k, &alpha, A, &lda, B, &ldb, &beta, C, &ldc);
Or through the C-Interface:
cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, m, n, k, alpha, A, lda, B, ldb, beta, C, ldc);
So for computing C = A*B you choose alpha=1 and beta = 0.
And you should only call it if A, B, C are not only different names but also refer so separate memory blocks.
So this is a very simple, almost primitive, interface.
And that’s what makes it great.
Because providing an efficient implementation (close to peak performance) is not that trivial. But with a narrow interface (e.g. all elements of the same type) at least feasible.
What you do in the implementation is not some Strassen algorithm. In short:
- You compute the matrix product block-wise (so that you can exploit the cache hierarchy)
- On the smallest block (that fit in the L1 cache) you apply architecture specific micro kernels
Two world in one …
Eigen actually does both. It provides matrix/vector classes and implements blocked matrix operations with platform specific micro kernels.
That’s great.
But still, I think it is of value to also have something which is a layer that brings them together.
ulmBLAS, for example, is kind of a prototype for this idea:
- on top high-level libraries can be build
- at the bottom the architecture specific stuff integrated
Back in 2016 (yes most of the code of ulmBLAS is from around 2014) I made experiments on how higher level libraries can make use of ulmBLAS:
- Boost.uBLAS and
- Blaze.
On the high-level part you can do crazy things, like matrix classes where elements are not stored in memory, but instead, computed when you access elements. And still, you can achieve a pretty good performance.
And other stuff like mixed element types. Where A, B, C, alpha, beta can have different types. So unless you make copies, you can’t do the operation with BLAS. But in the ulmBLAS layer you can deal with that when matrix blocks get packed and do the type promotions there with little overhead.
r/cpp • u/13steinj • 27d ago
What would it take to leave ISO?
With the conclusion of the DIS ballot, I think that no matter what side you're on, this should be (hopefully the final) wake up call that stayint in ISO under its process is untenable. If you're pro-contracts you probably see this as minority rule. If you're against, congrats-- the same game can be played against the feature you want in the future.
I see 3 possible results out of Brazil:
- Contracts are pulled, fight to see another day [and/or leave ISO, and/or fork the language].
- Contracts stay, roughly as is. To my understanding FDIS is a final chance scenario, so I don't see this working out. Even "as a statement," it's not a good look and WG21 will eat the blame.
- Contracts are fixed enough to flip 4 NB votes (there's a number of combinations, but you need a minimum of 4 total flips from no/abstain -> yes).
It's my understanding that FDIS is a "last chance" for 26. Personally, considering what else is in 26 (for me, reflection), I'd rather go with the first option. That begs the question: where do we go from here?
Continue with the current process, which has unearthed pain points and nasal demons every few years, or break up with the ISO process (this doesn't even have to be a clean break, just something closer to ECMAScript's process)?
If so, what would it take? Alternatively, if we could, what would we actually lose? What would we gain (besides more control of process)?
Obligatory "no sarcastic comments about getting a TARDIS and changing it back then."
r/cpp • u/hellfoundry • 27d ago
slughorn: C++20 library implementing the Slug GPU vector-graphics technique
github.comr/cpp • u/boostlibs • 27d ago
CppCon Anyone Can Contribute to Boost: Demystifying C++ Maintainership | Arnaud Becheler - CppCon 2026
youtu.ber/cpp • u/benjoffe • 27d ago
A faster way to compute signed 64-bit floor division by constants
benjoffe.com
r/cpp
•
u/ProgrammingArchive
•
28d ago
New C++ Conference Videos Released This Month - October 2026 (Updated To Include Videos Released 2026-10-19 - 2026-10-25)
C++Day
2026-10-19 - 2026-10-25
- C++26 Execution Control: An Introduction (Alberto Barbati) - https://www.youtube.com/watch?v=U4b8yO5L5JY
- Interesting Allocators in Games (Sergei Kushnirenko) - https://www.youtube.com/watch?v=6fWwaLMgC94
- From legacy code to a registry of modern algorithms (Roberta Cisotti) - https://www.youtube.com/watch?v=u_FZatqHFAk
- Zero-Overhead Dispatch: Leveraging __musttail and Custom ABI in C++ - https://www.youtube.com/watch?v=2N7ALplaMC4&pp=0gcJCTAMAYcqIYzv
C++Now
2026-10-19 - 2026-10-25
- C++ Magic Statics Demystified - History, Internals, Pitfalls, and Optimizations - Chandranath Bhattacharyya - https://youtu.be/kV6TbuRMIVg
- Code C++ Like a Library Author - Jon Kalb - https://youtu.be/LgTEvW61J70
- CMake’s Recent Evolution - Modules, CPS, and Build Optimization - Bill Hoffman - https://youtu.be/aas2DSxHrT8
2026-10-12 - 2026-10-18
- Implementing Logic in C++ - Hans de Nivelle - https://youtu.be/3ffgtI31iKw
- The Secret to C++ Reflection Now: CMake Code Generation - Bret Brown - https://youtu.be/OW_h9oyHQ-0
- Co-Designing Integrated AI-Enabled Compiler-Runtime Systems - Hartmut Kaiser - https://youtu.be/cIt4D_SJcI8
2026-10-05 - 2026-10-11
- Signal Trees - A Deep Dive into a High-Performance Alternative to Queue-Based Task Scheduling - Michael Maniscalco - https://youtu.be/ZRd_XN3LGxo
- Object Oriented Programming in Contemporary C++ - Steve Downey - https://youtu.be/m7gwSr27m74
- Cutting Some Slack for our Programs - Lisa Lippincott - https://youtu.be/xwnRPyRK5h4
2026-09-28 - 2026-10-04
- What Every C++ Programmer Needs to Know About AI - Jody Hagins - https://youtu.be/ZBXHPKVCa8E
- SPL - Open Source, Constexpr Library for Composing Algorithms - John Bandela - https://youtu.be/96AGjm3uwko
- Senders For Existing Asynchronous Interfaces - Dietmar Kühl - https://youtu.be/KB5Nfofgu2k
ACCU
2026-10-19 - 2026-10-25
- Serial C++ Can Be Parallel Too - Eran Gilad - https://youtu.be/4amZ_ZWqpA8
- C++ Magic Statics Demystified - History, Internals, Pitfalls, and Optimizations - Kathleen Baker & Chandranath Bhattacharyya - https://youtu.be/h40xp211BCw
- What static, inline, const, constexpr Mean and When to Use Them - Andreas Fertig - https://youtu.be/u8te1UQOxQY
2026-10-12 - 2026-10-18
- Dependency Injection and Dependency Inversion - C++ Perspective - Vladimir Vishnevskii - https://youtu.be/hzD9k4BZCE4
- AI Writes All Your Code Now - How Will You Ever Debug It? - Greg Law & Mark Williamson - https://youtu.be/-hTG9Jp_2PU
- The Not-So-Hidden Corners of C++ ABI Stability - Luis Caro Campos - https://youtu.be/3nd4RIH5okA
2026-10-05 - 2026-10-11
- Real-time Safety in C & C++ - Guaranteed by the Compiler! - Anders Schau Knatten - https://youtu.be/FeYEO3PhEVY
- Modernizing Legacy Codebases Without Stopping the World - Peter Muldoon - https://youtu.be/w9k-L0GLLKM
- Our Journey Toward a Fully Backward-Compatible, UB-Safe, ISO C++ - John Lakos - https://youtu.be/whFzmXXhG5g
2026-09-28 - 2026-10-04
- Refactoring Towards Structured Concurrency - Roi Barkan - https://youtu.be/ttoQfPP_Gkg
- Design Patterns - The Most Common Misconceptions (3 of N) - Klaus Iglberger - https://youtu.be/bAsJvmtYZOg
- One Lib to Rule Them All and in the Darkness bindgen… - Antonello Palazzi & Kay Hicketts - https://youtu.be/9BpVjPKv02s
ADC
2026-10-19 - 2026-10-25
- Introducing LYDIA Phase2 - Kazuyoshi Sasamori, Alfie Bradic & Paul McCabe - https://youtu.be/MyCMBiWAEqM
- FPGA-Based Alias-Free Oscillator - 岡安啓幸 / Akiyuki Okayasu - https://youtu.be/OXB5crrpFgc
- Type-Erased Audio Parameters - A New Approach to an Old Problem - Jan Wilczek - https://youtu.be/K-38Zpf13lQ
2026-10-12 - 2026-10-18
- Introduction of the Technologies That Make Up Project LYDIA - Taichi Kumon & Tom Baker - https://youtu.be/-Cyht3g4H1s
- AI for Circuit Modeling - 村井 勝吾 / Shogo Murai - https://youtu.be/IL08vd0EiFY
- MIDI 2.0 - Ready to Ship - Brett g Porter - https://youtu.be/RGLtRZC--34
2026-10-05 - 2026-10-11
- BEEPS and PORTS - Annoy Everyone in Your House While Building An Audio Synthesizer - Joseph Stewart - https://youtu.be/bnIV2nyh-rg
- Hardware DSP Asset Inheritance and Evolution - Takeshi Kuwahara - https://youtu.be/yYukJpiFOOU
- Field Recording - In Search for Perfect Sounds - Malin Arvidsson - https://youtu.be/L5iZDi71VWU
2026-09-28 - 2026-10-04
- Designing Interactive Music Experiences in XR - Kasson Crooker - https://youtu.be/J3sVHT8luKs
- When (Not) to Patent Audio Software - Simon Hestermann - https://youtu.be/stBB1JoKQiY
- Distribution Strategies for Indie Audio Developers - From Plugin to Product - Dani Karanyi - https://youtu.be/Piar49uTjtg
r/cpp • u/tartaruga232 • 29d ago
Do not remove Contracts from C++26
open-std.orgDocument #: P4433R0
Quotes:
It has come to our attention that during the DIS ballot, a small number of individuals have actively lobbied NBs against approving the C++26 DIS due to their own sustained opposition to contract assertions, a new language feature added in C++26. These lobbying activities have been accompanied by a public petition [Falco26] addressing NBs directly, a paper [P4334R0] that describes "fundamental flaws" in contract assertions, and other papers 2 published around the same time by the same authors or a subset thereof.
The petition [Falco26] and the papers accompanying it contain a number of claims, including that C++26 contract assertions lack genuine consensus in WG21; that the design is hasty; that technical objections were not given a proper hearing; and/or that alternative designs were not considered. These claims are not true.
In addition, the description of C++26 contract assertions given in [P4334R0] contains a number of inaccuracies. It misrepresents the specification itself, 3 the amount of wording it consists of, 4 its design intent, 5 how it relates to hardening 6 and static analysis, 7 its existing implementations, 8 existing practice, 9 teachability, 10 and proposed extensions. 11 None of the listed concerns are new; they have all been previously published by those authors (or a subset thereof), presented to WG21, and extensively discussed there. 12
Related post: https://www.reddit.com/r/cpp/comments/1xeeevt/balloting_has_completed_for_c26_unfortunately_it/
Note that I have no opinion on the topic myself. I'm just trying to understand what happened.