TGViewer
Channel Public Channel
C++ - Reddit

C++ - Reddit

@r_cpp

Stay up-to-date with everything C++!
Content directly fetched from the subreddit just for you.

Join our group for discussions : @programminginc

Powered by : @r_channels
Subscribers
229
Photos
48
Videos
8
Links
25.4K
Recent Posts 20 shown
Post #25720 14
myStringStream.str("") Considered Harmful Under C++20

I was recently looking at some (rather old) code that was relying on std::ostringstream in a large, performance senstive loop. (Yes, I know using iostreams in performance sensitive code is a bad idea, but legacy code exists.)

The code was using a common pattern to reset a ostringstream instance each time through the loop to avoid having to construct a new instance every time.

std::ostringstream oss;
for(const MyType & value : values)
{
oss << value;
doSomethingWithString(oss.str());
// Assign an empty string to the internal buffer. This should reset
// the size to zero, but keep the allocated buffer. In older code,
// you often see this written as oss.str("").
oss.str({});
oss.clear(); // Reset the stream
}

When migrating the code to C++20, I was excited to use the new std::ostringstream::view() getter to skip an unnecessary copy of the std::string out of the stream's internal buffer.

std::ostringstream oss;
for(const MyType & value : values)
{
oss << value;
doSomethingWithStringView(oss.view());
oss.str({});
oss.clear();
}

Then I noticed that the std::ostringstream::str setter gained an r-value reference overload in C++20. That would let us pre-allocate our string buffer just once. Nice!

std::ostringstream oss;
{
std::string buffer;
buffer.reserve(1024);
oss.str(std::move(buffer));
}
for(const MyType & value : values)
{
oss << value;
doSomethingWithStringView(oss.view());
oss.str({});
oss.clear();
}

But wait. That means that the oss.str({}) call inside the loop is doing the exact same thing. So it's wiping out our allocation every time through the loop! Uh oh.

It seems that to clear the internal buffer while keeping its allocation, one must now explicitly call the const reference overload of str().

const std::string empty;
std::ostringstream oss;
{
std::string buffer;
buffer.reserve(1024);
oss.str(std::move(buffer));
}
for(const MyType & value : values)
{
oss << value;
doSomethingWithStringView(oss.view());
oss.str(empty);
oss.clear();
}

So if your codebase uses std::ostringstream, you might want to do a quick grep for str("") and str({}) to see if the upgrade to C++20 silently caused you to start throwing away your stream buffers over and over again.

https://redd.it/1wp1ydk
@r_cpp
Reddit From the cpp community on Reddit Explore this post and more from the cpp community
Post #25719 21
A clever branch free optimization

I'm the developer of memlz which is an extremely fast compression library.

We have `char* src, char* dst` for the source and destination buffers and `uint16_t flags` that we prepend bits to one at a time. The inner core looks something like this (pseudo code):

flags <<= 1;
uint64_t payload = ((uint64_t*)src)[i];
uint16_t hash_index = hash_function(payload);
if (hash_table[hash_index] == payload) {
flags |= 1;
*(uint16_t*)dst = (uint16_t)hash_index;
dst += sizeof(uint16_t);
}
else {
*(uint64_t*)dst = payload;
hash_table[hash_index] = payload;
dst += sizeof(uint64_t);
}

Depending on a hash comparison we need to output either 2 or 8 bytes, advance `dst` accordingly and prepend either a 1 or a 0 to `flags`.

Furthermore, at the end it's required that `hash_table[hash_index] == payload`, so we update `hash_table` in the false-case.

Let's benchmark it with 211 MB input so it's uncached:

memlz: 2744 MB/s

Now let's look at an amazing idea. The output to `*dst` can be rewritten with the ternary operator:

`*(uint64_t*)dst = hit ? hash_index : payload;`

That turns into a compare instruction (`cmp`) and a conditional move instruction (`cmove`) with no branching:

00007FF742A5A55B mov rax,r10
00007FF742A5A55E cmp rcx,r10
...
00007FF742A5A56D cmove rax,rdx
00007FF742A5A571 mov qword ptr [rdi],rax

The advancement of `dst` is also simple to make branchless, noting that `hit` will turn either 0 or 1:

uint64_t hit = (hash_table[hash_index] == payload);
dst += 8 - (hit * 6);

Now look at updating the `hash_table` where we update it to `payload` only if it differed from `payload`. What we can do is update it unconditionally at the end, and hope that the extra number of unnecessary writes to memory (where it just overwrites the same value) are not too expensive.

Final branch-free version:

uint64_t payload = ((uint64_t*)src)[i];
uint16_t hash_index = hash_function(payload);
flags <<= 1;
uint64_t hit = (hash_table[hash_index] == payload);
flags |= hit;
*(uint64_t*)dst = hit ? hash_index : payload;
hash_table[hash_index] = payload;
dst += 8 - (hit * 6);

Let's benchmark it:

memlz: 4269 MB/s

I had never believed such gains were possible because I had been micro-optimizing on this for weeks.

I later achieved 5070 MB/s. To put it in perspective, uncached memcpy runs at 14000 MB/s here and LZ4 - another popular fast compression library - at 718 MB/s.

https://redd.it/1wkuou2
@r_cpp
Reddit From the cpp community on Reddit Explore this post and more from the cpp community
Post #25715 44
C++ Show and Tell - September 2026

Use this thread to share anything you've written in C++. This includes:

* a tool you've written
* a game you've been working on
* your first non-trivial C++ program

The rules of this thread are very straight forward:

* The project must involve C++ in some way.
* It must be something you (alone or with others) have done.
* Please share a link, if applicable.
* Please post images, if applicable.

If you're working on a C++ library, you can also share new releases or major updates in a dedicated post as before. The line we're drawing is between "written in C++" and "useful for C++ programmers specifically". If you're writing a C++ library or tool for C++ developers, that's something C++ programmers can use and is on-topic for a main submission. It's different if you're just using C++ to implement a generic program that isn't specifically about C++: you're free to share it here, but it wouldn't quite fit as a standalone post.

Last month's thread: https://www.reddit.com/r/cpp/comments/1vhdqw8/c_show_and_tell_august_2026/

https://redd.it/1w776o7
@r_cpp
Reddit From the cpp community on Reddit Explore this post and more from the cpp community
Post #25713 39
Time-Varying Convolution - Anton Lundberg - https://youtu.be/iT0olrM1iyU
Building an Optimized DSP Framework in Modern C++ - Scott Carver - [https://youtu.be/k4yxNxNCo0k](https://youtu.be/k4yxNxNCo0k)

2026-08-03 - 2026-08-09

Commercialising Audio Plugins - Going From Development to Sales and Beyond - Tobias Lønnerød Madsen - https://youtu.be/SWPLyDDBU38
Capturing and Transferring Expressive Microtiming in Drumming - Eemi Fagerlund - [https://youtu.be/4ZAJHl02X7s](https://youtu.be/4ZAJHl02X7s)
How I Learned to Love the Docs - Documentation As Design Process for Music Tech Products - Astrid Bin - https://youtu.be/7MpDAHd7rbw

2026-07-27 - 2026-08-02

Workshop: Programming Music and Synthesizers on-the-fly with Pharo - Domenico Cipriani - [https://youtu.be/v95QYyUHNJ8](https://youtu.be/v95QYyUHNJ8)
PolyBLEP & PolyBLAMP Demystified - Nis Wegmann - https://youtu.be/\_bW8TfgEqRM
Modernizing Legacy Audio Plugin Codebases - Lessons from FL Studio’s Plugin Suite - Tomas Medek - [https://youtu.be/zY8uHzAdnzk](https://youtu.be/zY8uHzAdnzk)
How to Write Scalable, Deterministic Audio Engines - Janus Lynggaard Thorborg - https://youtu.be/3FXQQmQa-ak

https://redd.it/1vx94b9
@r_cpp
YouTube Real-Time Raytraced Acoustics for Games - Anton Lundberg - ADCx Copenhagen 2026 https://audio.dev/ -- @audiodevcon​ --- Real-Time Raytraced Acoustics for Games: Dynamic Reverb with IR Synthesis & Time-Varying Convolution - Anton Lundberg - ADCx Copenhagen 2026 --- Real-time acoustics in games is often a trade-off: either dynamic, geometry…
Post #25712 27
New C++ Conference Videos Released This Month - August 2026 (Updated To Include Videos Released 2026-08-17 - 2026-08-23)

C++Now

2026-08-17 - 2026-08-23

Coroutines for Dummies - Dominic Fischer - [https://youtu.be/apLDto3FUVA](https://youtu.be/apLDto3FUVA)
Compile-Time Borrow Checker with Stateful Metaprogramming - Alon Wolf - https://youtu.be/3hL8mh0K8-I
Algorithms for Trees - Foldable, Applicative, Traversable - Steve Downey - [https://youtu.be/vfXKH7Uj170](https://youtu.be/vfXKH7Uj170)

2026-08-10 - 2026-08-16

After Reflection: The Runtime Story - Saksham Sharma - https://youtu.be/bUmt9K1o1d0
A Little Introduction to Control Flow Integrity in C++ - James McNellis - [https://youtu.be/FNHMwi\_0psQ](https://youtu.be/FNHMwi_0psQ)
Towards Async Everything Part 1 - Senders as the Lowest Layer - Robert Leahy - https://youtu.be/3PI31yqjI\_w
Towards Async Everything Part 2 - Scopes, Construction, and Destruction - Robert Leahy - Robert Leahy - [https://youtu.be/Hgdikbfu9UE](https://youtu.be/Hgdikbfu9UE)

2026-08-03 - 2026-08-09

How To Make Formal Methods A Software Quality Solution That Can Actually Be Used In The Industry - Steve Barriault - https://youtu.be/OYwDdMCCDIM
Link What You Include - Maintain a Coherent CMake Target Model - Frank Miller - [https://youtu.be/ssTG6uzxXm4](https://youtu.be/ssTG6uzxXm4)
Scaling beman.exemplar - Eddie Nolan - https://youtu.be/xylmqy1VAwo

2026-07-27 - 2026-08-02

Beautiful C++ Code - Told Through the Eyes of A Failed AI Prompt - Erich Lohrmann - [https://youtu.be/Kq4W3Y5gTI8](https://youtu.be/Kq4W3Y5gTI8)
A Path to Practically Safe C++ - Yitzhak Mandelbaum - https://youtu.be/fi6csDXvve0
When Abstractions Fix Too Much - Towards Flexible Library Design - Patrick Roberts - [https://youtu.be/IKIyFUcVvis](https://youtu.be/IKIyFUcVvis)

C++Online

2026-08-17 - 2026-08-23

Lightning Talk: Bazelizing a C++ Project - Paulo Chiliguano - https://youtu.be/agAbiQydcOQ
Lightning Talk: Can We Still Find Joy in Programming? - Sandor Dargo - [https://youtu.be/WxqeLwyw0KM](https://youtu.be/WxqeLwyw0KM)

2026-08-10 - 2026-08-16

Lightning Talk: Saving Time With Runtime and Having Registry Level Synthesis of Your Software As You Write It - Michael Hubbard - https://youtu.be/B0JJwWMUzzw
Lightning Talk: 2 New Nice CMake Features I Learned in 2025 - Lieven de Cock - [https://youtu.be/YnWJyHxHpBc](https://youtu.be/YnWJyHxHpBc)

2026-08-03 - 2026-08-09

Lightning Talk: Your Docs Have a New Reader (and It Hallucinates) - Paul Wicking - https://youtu.be/DbL6XPMlw-o
Lightning Talk: RPC With Coroutines, RAII and Callable Weakpointers - Edward Boggis-Rolfe - [https://youtu.be/m70hb5YgabQ](https://youtu.be/m70hb5YgabQ)

2026-07-27 - 2026-08-02

Dynamic Asynchronous Tasking with Dependencies - Tsung-Wei (TW) Huang - https://youtu.be/4LzQHw7jz2g
C++/sys - A Standard Library Projection to Facilitate the Verification of Run-time Memory Safety - Karsten Pedersen - [https://youtu.be/dF7RwJw\_G8c](https://youtu.be/dF7RwJw_G8c)

ADC

2026-08-17 - 2026-08-23

How To Distribute Your Plugins - Using MuseHub as the Engine To Get Your Audio Tools in the Hands of Millions - Khaled Said - https://youtu.be/CQTblE1xHto
Incline - Topographic Microsound Explorer - Cristián Vogel - [https://youtu.be/lJA00sRFhGg](https://youtu.be/lJA00sRFhGg)
Optimizing UI Rendering Performance in Cubase and Nuendo - Erich Krey - https://youtu.be/Oz1dZLcXVjs

2026-08-10 - 2026-08-16

Measuring and Improving UI Performance with the JUCE C++ Framework - Anthony Nicholls - [https://youtu.be/0n9x6R0fheo](https://youtu.be/0n9x6R0fheo)
Real-Time Raytraced Acoustics for Games: Dynamic Reverb with IR Synthesis &
YouTube Coroutines for Dummies - Dominic Fischer - C++Now 2026 https://www.cppnow.org​ --- Coroutines for Dummies - Dominic Fischer - C++Now 2026 --- C++20 coroutines are a game-changer for writing asynchronous code and generators, but they come with a steep learning curve. This talk is designed to simplify the concept…
Post #25709 30
Is there a way to track reflection support status in Clang?

(I'm going to be bold and assume the "no questions" rule is for questions about specific code, not about discussing the language itself)



I am extremely happy that we have reflection in C++26, however currently it is GCC only. I am using Clang on all platforms, so I am curious about when it will get reflection.



I tried searching and I found a bunch of experimental forks with reflection. I am not sure if those track the current version of reflection and whether one of these is going to be merged, or if a new implementation will be created. Github issues basically say "we get it when we get it" and link to LLVM discourse. On discourse I found just a thread that a meeting on reflection was held in December.


Do you know either when we are getting reflection, or if there is some way to track its progress for outside observers? Thanks!

https://redd.it/1vsmdo9
@r_cpp
Reddit From the cpp community on Reddit Explore this post and more from the cpp community
Post #25707 30
Post #25706 18
New C++ Conference Videos Released This Month - August 2026 (Updated To Include Videos Released 2026-08-10 - 2026-08-16)

**C++Now**

2026-08-10 - 2026-08-16

* After Reflection: The Runtime Story - Saksham Sharma - [https://youtu.be/bUmt9K1o1d0](https://youtu.be/bUmt9K1o1d0)
* A Little Introduction to Control Flow Integrity in C++ - James McNellis - [https://youtu.be/FNHMwi\_0psQ](https://youtu.be/FNHMwi_0psQ)
* Towards Async Everything Part 1 - Senders as the Lowest Layer - Robert Leahy - [https://youtu.be/3PI31yqjI\_w](https://youtu.be/3PI31yqjI_w)
* Towards Async Everything Part 2 - Scopes, Construction, and Destruction - Robert Leahy - Robert Leahy - [https://youtu.be/Hgdikbfu9UE](https://youtu.be/Hgdikbfu9UE)

2026-08-03 - 2026-08-09

* How To Make Formal Methods A Software Quality Solution That Can Actually Be Used In The Industry - Steve Barriault - [https://youtu.be/OYwDdMCCDIM](https://youtu.be/OYwDdMCCDIM)
* Link What You Include - Maintain a Coherent CMake Target Model - Frank Miller - [https://youtu.be/ssTG6uzxXm4](https://youtu.be/ssTG6uzxXm4)
* Scaling beman.exemplar - Eddie Nolan - [https://youtu.be/xylmqy1VAwo](https://youtu.be/xylmqy1VAwo)

2026-07-27 - 2026-08-02

* Beautiful C++ Code - Told Through the Eyes of A Failed AI Prompt - Erich Lohrmann - [https://youtu.be/Kq4W3Y5gTI8](https://youtu.be/Kq4W3Y5gTI8)
* A Path to Practically Safe C++ - Yitzhak Mandelbaum - [https://youtu.be/fi6csDXvve0](https://youtu.be/fi6csDXvve0)
* When Abstractions Fix Too Much - Towards Flexible Library Design - Patrick Roberts - [https://youtu.be/IKIyFUcVvis](https://youtu.be/IKIyFUcVvis)

**C++Online**

2026-08-10 - 2026-08-16

* Lightning Talk: Saving Time With Runtime and Having Registry Level Synthesis of Your Software As You Write It - Michael Hubbard - [https://youtu.be/B0JJwWMUzzw](https://youtu.be/B0JJwWMUzzw)
* Lightning Talk: 2 New Nice CMake Features I Learned in 2025 - Lieven de Cock - [https://youtu.be/YnWJyHxHpBc](https://youtu.be/YnWJyHxHpBc)

2026-08-03 - 2026-08-09

* Lightning Talk: Your Docs Have a New Reader (and It Hallucinates) - Paul Wicking - [https://youtu.be/DbL6XPMlw-o](https://youtu.be/DbL6XPMlw-o)
* Lightning Talk: RPC With Coroutines, RAII and Callable Weakpointers - Edward Boggis-Rolfe - [https://youtu.be/m70hb5YgabQ](https://youtu.be/m70hb5YgabQ)

2026-07-27 - 2026-08-02

* Dynamic Asynchronous Tasking with Dependencies - Tsung-Wei (TW) Huang - [https://youtu.be/4LzQHw7jz2g](https://youtu.be/4LzQHw7jz2g)
* C++/sys - A Standard Library Projection to Facilitate the Verification of Run-time Memory Safety - Karsten Pedersen - [https://youtu.be/dF7RwJw\_G8c](https://youtu.be/dF7RwJw_G8c)

**ADC**

2026-08-10 - 2026-08-16

* Measuring and Improving UI Performance with the JUCE C++ Framework - Anthony Nicholls - [https://youtu.be/0n9x6R0fheo](https://youtu.be/0n9x6R0fheo)
* Real-Time Raytraced Acoustics for Games: Dynamic Reverb with IR Synthesis & Time-Varying Convolution - Anton Lundberg - [https://youtu.be/iT0olrM1iyU](https://youtu.be/iT0olrM1iyU)
* Building an Optimized DSP Framework in Modern C++ - Scott Carver - [https://youtu.be/k4yxNxNCo0k](https://youtu.be/k4yxNxNCo0k)

2026-08-03 - 2026-08-09

* Commercialising Audio Plugins - Going From Development to Sales and Beyond - Tobias Lønnerød Madsen - [https://youtu.be/SWPLyDDBU38](https://youtu.be/SWPLyDDBU38)
* Capturing and Transferring Expressive Microtiming in Drumming - Eemi Fagerlund - [https://youtu.be/4ZAJHl02X7s](https://youtu.be/4ZAJHl02X7s)
* How I Learned to Love the Docs - Documentation As Design Process for Music Tech Products - Astrid Bin - [https://youtu.be/7MpDAHd7rbw](https://youtu.be/7MpDAHd7rbw)

2026-07-27 - 2026-08-02

* Workshop: Programming Music and Synthesizers on-the-fly with Pharo - Domenico Cipriani - [https://youtu.be/v95QYyUHNJ8](https://youtu.be/v95QYyUHNJ8)
* PolyBLEP & PolyBLAMP Demystified - Nis Wegmann - [https://youtu.be/\_bW8TfgEqRM](https://youtu.be/_bW8TfgEqRM)
* Modernizing Legacy Audio Plugin Codebases - Lessons from FL Studio’s Plugin Suite - Tomas Medek -
YouTube After Reflection: The Runtime Story - Saksham Sharma - C++Now 2026 https://www.cppnow.org​ --- After Reflection: The Runtime Story - Saksham Sharma - C++Now 2026 --- C++ has enormous low-level power, but lacks a standardized meta-DSL-layer: portable reflection-ish primitives for defining and “compiling” DSLs at runtime…
Post #25705 37
C++ Show and Tell - August 2026

Use this thread to share anything you've written in C++. This includes:

* a tool you've written
* a game you've been working on
* your first non-trivial C++ program

The rules of this thread are very straight forward:

* The project must involve C++ in some way.
* It must be something you (alone or with others) have done.
* Please share a link, if applicable.
* Please post images, if applicable.

If you're working on a C++ library, you can also share new releases or major updates in a dedicated post as before. The line we're drawing is between "written in C++" and "useful for C++ programmers specifically". If you're writing a C++ library or tool for C++ developers, that's something C++ programmers can use and is on-topic for a main submission. It's different if you're just using C++ to implement a generic program that isn't specifically about C++: you're free to share it here, but it wouldn't quite fit as a standalone post.

Last month's thread: https://www.reddit.com/r/cpp/comments/1umnaxs/c_show_and_tell_july_2026/

https://redd.it/1vhdqw8
@r_cpp
Reddit From the cpp community on Reddit Explore this post and more from the cpp community
Post #25702 31
Older posts →

About this channel

How can I read @r_cpp without a Telegram account?
TGViewer shows the public web preview Telegram publishes for C++ - Reddit: recent posts, photos, videos and the subscriber count, with no app, login or account.
How many subscribers does C++ - Reddit have?
C++ - Reddit (@r_cpp) has 229 subscribers on Telegram, refreshed roughly every 30 minutes.
Does C++ - Reddit know I viewed it here?
No. Public channel previews carry no viewer identity, and TGViewer has no accounts or tracking of what you look up.
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →