-
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
When maps map iterators are invalidated after insert.
This issue surprised me today and it is related to reverse iterators.
On the emplace reference page it is fairly clear:
> No iterators or references are invalidated.
Same with insert, with a caveat relating to node handles.
But apparently, this does not apply to rend():
https://godbolt.org/z/zeTznKq6K
Perhaps I am just ignorant of how map reverse iterators work but I've never picked up on this before. It was actually debugging in MSVC which led me to it and wouldn't allow the comparison ritr == map.rend() at all, so is it actually UB?
https://redd.it/1ncn921
@r_cpp
Clang 16 on Ubuntu 22.04 fails to run (missing libtinfo.so.5) — need a solution without upgrading or installing libtinfo5
Hey folks,
I’m maintaining a C++ project that currently builds with inbuilt Clang 16. We tried upgrading to Clang 21, but there are way too many build errors, so upgrading isn’t an option right now.
The issue is that when running Clang 16 on Ubuntu 22.04, I get this error (clang: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory).
Ubuntu 22.04 only ships libtinfo6, and my client doesn’t want to install the older libtinfo5 package on their build machine.
I need to keep Clang 16 but also make it work without installing libtinfo5.
Has anyone solved this cleanly?
Thanks in advance!
https://redd.it/1ncelpd
@r_cpp
Why the hate for memory safety?
Hi, I'm coming from rust and I just recently heard the news about how C++ is considering memory safety, yet from my observation c++ doesn't want it. I'm a little perplexed by this, isn't the biggest ( probably dangerous) feature of c++ is the danger of memory leaks and such. Wouldn't that fix or make c++ objective better?
https://redd.it/1nbzpj3
@r_cpp
Entry Level Jobs
Hi, I’m a final-year bachelor’s student from India, and I’m trying to figure out how to look for entry-level C++ roles. My C++ knowledge is decent for a college student, though I know I still have a lot to improve. I’m learning and practicing every day, but I feel stuck when it comes to finding jobs or internships.
https://redd.it/1nbnaem
@r_cpp
Seq Library v2 release
Hi everyone,
The version 2 of the seq library has been released at https://github.com/Thermadiag/seq
Seq is a (now header-only) C++17 library providing original STL-like containers and related tools like:
\- seq::flat_set/map: An ordered flat map similar to std::flat_map or boost::container::flat_map, but with fast insertion/deletion of single elements.
\- seq::radix_set/map: ordered map using a Burst Trie derivative with (usually) very fast performances for all types of workload.
\- seq::radix_hash_set/map: radix-based hash map with incremental rehash and low memory footprint.
\- seq::ordered_set/map: hash map that preserves insertion order with stable references/iterators.
\- seq::concurrent_set/map: highly scalable concurrent hash map with an interface similar to boost::concurrent_flat_map (and increased performances according to my benchmarks).
\- Random-access containers: seq::devector and seq::tiered_vector.
\- seq::tiny_string: relocatable string-like class with customizable SSO.
Feel free to try/share/comment/correct!
Bests
https://redd.it/1nbiwie
@r_cpp
Meson modules support: initial modules support with Clang and example project. Dependency resolution, partitions and import std.
Hello everyone,
I have been working in modules support for Meson build system lately in a branch. I am focusing on Clang support as a first step (gcc should follow). Tested in Homebrew Clang 19, feedback is welcome.
I have reached a point where the branch can:
- 'import std' and use it.
- generate all dependencies via clang-scan-deps and do correct resolution.
The targets are used as usual (a library target, etc.)
PR is here: https://github.com/mesonbuild/meson/pull/14989
## What it does currently.
clang-scan-deps does a bulk scan of the whole compilecommands.json database file and determines which file provides and requires each module, globally.
Resolution order works by adding ninja build rules and dyndep resolution (except if you find any bugs or corner cases, but at least for my project it has worked correctly so far).
## How you can try it
You can download the latest commit of your branch.
Note that clang-scan-deps must be installed and found in your path and you need Clang >= 17, though Clang 19 is what I tested and recommend.
Your target should have a flat structure inside your directory as of now, and relies on the following conventions:
- your primary interface unit for your module should always
be called 'module.cppm'. It should export module 'target-name'.
- your interface partitions can have any name supported by a module.
For example: MyThings.cppm. The interface partition
should declare 'export module target-name:MyThings'.
- Your importable interface implementation units should end with
'Impl.cppm'. For example 'MyThingsImpl.cppm'. This should
'module target-name:MyThings' (without export).
- Your non-importable implementation can have any name with an
extension .cpp, not a .cppm, since implementation units are
not importable. It is highly recommended, though, that if you
have a single implementation file, it is called moduleImpl.cpp.
It must do 'module target-name;'
- You can have regular (non-module) translation unit file
without any module declarations in your target and can
include files as usual, etc. incrementally, but for modules side
of things the conventions are as above.
There is also a project you can play with at the top-level comment attached, at the beginning.
Here is an example target with project as an example of how you should use it. Please, use a flat file structure inside your directory for your target, it is the convention for now:
Meson.build example (cppimportstd compiles the std module and implicitly adds the dependency to c++ targets):
```
project('Your project', 'cpp',
defaultoptions: 'cpp_std=c++23',
'buildtype=release',
'cpp_import_std=true',
version: '0.1')
# The directory does not need to have the name of the module,
# only the target itself
subdir('src/mymod')
meson.build in src/mymod
I made a custom container. Is this a good idea? (A smart_seq container)
https://github.com/illegal-instruction-co/smart_seq
https://redd.it/1nb8q9c
@r_cpp
Simulating stuff in C++
Hello guys, i’m a beginner in learning c++ and i am using a book called “Jumping into C++” by Alex Allain. In some practice problems I need to simulate some stuff like a visual tic-tac-toe game (with the square brackets) where you can play with 2 players, but the book doesn’t seem to tell me how I can make these brackets or how to turn input like a ‘X’ or ‘O’ in the output so that you can see the brackets with either X or O’s in them. Does anyone know anything about how to make such games (or know a good video about it)? Thanks in advance
https://redd.it/1mxam8k
@r_cpp
Heterogeneous Message Handler
https://biowpn.github.io/bioweapon/2025/08/20/heterogeneous-message-handler.html
https://redd.it/1mx4nyr
@r_cpp
The power of C++26 reflection: first class existentials
tired of writing boilerplate code for each existential type, or using macros and alien syntax in proxy?
C++26 reflection comes to rescue and makes existential types as if they were natively supported by the core language. https://godbolt.org/z/6n3rWYMb7
#include <print>
struct A {
double x;
auto f(int v)->void {
std::println("A::f, {}, {}", x, v);
}
auto g(std::stringview v)->int {
return staticcast<int>(x + v.size());
}
};
struct B {
std::string x;
auto f(int v)->void {
std::println("B::f, {}, {}", x, v);
}
auto g(std::stringview v)->int {
return x.size() + v.size();
}
};
auto main()->int {
using CanFAndG = struct {
auto f(int)->void;
auto g(std::stringview)->int;
};
auto x = std::vector<Ǝ<CanFAndG>>{ A{ 3.14 }, B{ "hello" } };
for (auto y : x) {
y.f(42);
std::println("g, {}", y.g("blah"));
}
}
https://redd.it/1mwv927
@r_cpp
Is it too late to get stuff into C++26?
With Deducing this being accepted into C++23 extension methods feel like a proposal just waiting to happen, and now that i finally got some time i want to take a stab at it. So my question is, should i do it right now and hope it gets accepted into C++26 or do i wait till C++29?
https://redd.it/1mw87tb
@r_cpp
Announcing Proxy 4: The Next Leap in C++ Polymorphism - C++ Team Blog
https://devblogs.microsoft.com/cppblog/announcing-proxy-4-the-next-leap-in-c-polymorphism/
https://redd.it/1mw2d3l
@r_cpp
Why use a tuple over a struct?
Is there any fundamental difference between them? Is it purely a cosmetic code thing? In what contexts is one preferred over another?
https://redd.it/1mvyjh3
@r_cpp
Create a simple calculator desktop app with C++
I've been researching the tools and software i need to download and install on my computer to create a simple desktop app with C++, but so far i'm still very confused. Can anyone give me an introductory guide on the steps i need to follow?
All I want is an icon on my desktop that, when double-clicked, opens a window with a basic calculator that performs the addition operation 2 + 2. Similar to the Windows 11 calculator, but made with C++ and by me.
I already have Visual Studio Code, and i've also installed the C/C++ extension. Do I need anything else for this simple desktop app project?
https://redd.it/1mvp6bx
@r_cpp
C++ Custom Stateful Allocator with Polymorphic std::uniqueptr
The code below compiles without warnings or errors on linux, windows, and macos. Why is it that ASAN reports:
==3244==ERROR: AddressSanitizer: new-delete-type-mismatch on 0x502000000090 in thread T0:
object passed to delete has wrong type:
size of the allocated type: 16 bytes;
size of the deallocated type: 8 bytes.
#0 0x7fe2aa8b688f in operator delete(void*, unsigned long) ../../../../src/libsanitizer/asan/asannewdelete.cpp:172
Is it right that there's an issue? If so, how can we implement custom stateful allocator with polymorphic std::unique\ptr? Thanks.#include <vector> #include <memory> #include <iostream>template <typename T> class mock_stateful_allocator { std::allocator<T> impl_; int id_; public: using value_type = T; using size_type = std::size_t; using pointer = T*; using const_pointer = const T*; using reference = T&; using const_reference = const T&; using difference_type = std::ptrdiff_t;mock_stateful_allocator() = delete;mock_stateful_allocator(int id) noexcept : impl_(), id_(id) { }mock_stateful_allocator(const mock_stateful_allocator<T>& other) noexcept = default;template <typename U> friend class mock_stateful_allocator;template <typename U> mock_stateful_allocator(const mock_stateful_allocator<U>& other) noexcept : impl_(), id_(other.id_) { }mock_stateful_allocator& operator = (const mock_stateful_allocator& other) = delete;T* allocate(size_type n) { return impl_.allocate(n); }void deallocate(T* ptr, size_type n) { impl_.deallocate(ptr, n); }friend bool operator==(const mock_stateful_allocator& lhs, const mock_stateful_allocator& rhs) noexcept { return lhs.id_ == rhs.id_; }friend bool operator!=(const mock_stateful_allocator& lhs, const mock_stateful_allocator& rhs) noexcept { return lhs.id_ != rhs.id_; } };template <typename Alloc> struct allocator_delete : public Alloc { using allocator_type = Alloc; using alloc_traits = std::allocator_traits<Alloc>; using pointer = typename std::allocator_traits<Alloc>::pointer; using value_type = typename std::allocator_traits<Alloc>::value_type;allocator_delete(const Alloc& alloc) noexcept : Alloc(alloc) { }allocator_delete(const allocator_delete&) noexcept = default;template <typename T> typename std::enable_if<std::is_convertible<T&, value_type&>::value>::type operator()(T* ptr) { std::cout << "type: " << typeid(*ptr).name() << "\n"; alloc_traits::destroy(*this, ptr); alloc_traits::deallocate(*this, ptr, 1); } };struct Foo { virtual ~Foo() = default; };struct Bar : public Foo { int x = 0; };int main() { using allocator_type = mock_stateful_allocator<Foo>; using deleter_type = allocator_delete<allocator_type>; using value_type = std::unique_ptr<Foo,deleter_type>;std::vector<value_type> v{};using rebind = typename std::allocator_traits<allocator_type>::template rebind_alloc<Bar>; rebind alloc(1); auto* p = alloc.allocate(1); p = new(p)Bar();v.push_back(value_type(p, deleter_type(alloc)));std::cout << "sizeof(Foo): " << sizeof(Foo) << ", sizeof(Bar): " << sizeof(Bar) << "\n"; }
https://redd.it/1mvlp85
@r_cpp
Practical CI-friendly Performance Tests
https://solidean.com/blog/2025/practical-performance-tests/
https://redd.it/1nclq2t
@r_cpp
Why we need C++ Exceptions
https://abuehl.github.io/2025/09/08/why-exceptions.html
https://redd.it/1ncb3qy
@r_cpp
New C++ Conference Videos Released This Month - September 2025
**C++Now**
2025-09-01 - 2025-09-07
* How to Build a Flexible Robot Brain One Bit at a Time - Ramon Perez - [https://youtu.be/akJznI1eBxo](https://youtu.be/akJznI1eBxo)
* Zngur - Simplified Rust/C++ Integration - David Sankel - [https://youtu.be/k\_sp5wvoEVM](https://youtu.be/k_sp5wvoEVM)
* Advanced Ranges - Writing Modular, Clean, and Efficient Code with Custom Views - Steve Sorkin - [https://youtu.be/5iXUCcFP6H4](https://youtu.be/5iXUCcFP6H4)
**ACCU Conference**
2025-09-01 - 2025-09-07
* The Hidden Techical Debt Crisis: When Non-Engineers Write Code - Felix Aldam-Gates - [https://youtu.be/VXb4n8FjcrE](https://youtu.be/VXb4n8FjcrE)
* The 10 Essential Features for the Future of C++ Libraries - Mateusz Pusz - [https://youtu.be/K-uzaG9S8bg](https://youtu.be/K-uzaG9S8bg)
* An Introduction To Go - Dom Davis - [https://youtu.be/l36Wqmw2JZo](https://youtu.be/l36Wqmw2JZo)
**C++ on Sea**
2025-09-01 - 2025-09-07
* Welcome to v1.0 of the meta::\[\[verse\]\]! - Inbal Levi - [https://youtu.be/Wbe09UFDvvY](https://youtu.be/Wbe09UFDvvY)
* To Err is Human - Robust Error Handling in C++26 - Sebastian Theophil - [https://youtu.be/A8arWLN54GU](https://youtu.be/A8arWLN54GU)
* The 10 Essential Features for the Future of C++ Libraries - Mateusz Pusz - [https://youtu.be/TJg37Sh9j78](https://youtu.be/TJg37Sh9j78)
**ADC**
2025-09-01 - 2025-09-07
* Current Approaches and Future Possibilities for Inter Audio Plugin Communication - Janos Buttgereit - [https://youtu.be/YHWdDLi6jgc](https://youtu.be/YHWdDLi6jgc)
* Keynote: Sonic Cartography - Navigating the Abstract Space-Time of Sound - Carla Scaletti - [https://youtu.be/iq75B8EkLv4](https://youtu.be/iq75B8EkLv4)
https://redd.it/1nbrhjg
@r_cpp
MapLibre Native (C++ SDK) now supports embedding into Slint apps
Thanks to yuiseki, there's now an official Slint integration available for MapLibre Native, the open-source C++ library for displaying maps. This means you can now embed MapLibre rendering directly into Slint based native GUI apps. The integration captures MapLibre Native rendered frames and presents them inside Slint UI components. The current MapLibre + Slint integration includes platform support for Windows, macOS, and Linux. Check out the GitHub repo - https://github.com/maplibre/maplibre-native-slint
https://redd.it/1nbn2hl
@r_cpp
Building C++ projects with the pixi package manager
https://prefix.dev/blog/pixi-build-for-cmake-projects
https://redd.it/1nbivvl
@r_cpp
Coming from Python, this is my first time learning C++. I know python fairly good till intermediate level. How should I start learning C++ ?
https://redd.it/1nbc6xp
@r_cpp
Allow Copilot to browse large C++ codebases intelligently and efficiently
Hey folks! I work with a really huge C++ codebase for work (think thousands of cpp files), and github copilot often struggles to find functions, or symbols and ends up using a combination of find and grep to look. Plus, we use the clangd server and not the cpp default intellisense, so there’s no way for copilot to use clangd. I created an extension that allows copilot to use the language server exposed by VS Code. When you press Ctrl+P and type in # with the symbol you’re searching for, Copilot can do it now using my extension. Also, it can now find all references, declaration or definition for any symbol. In a single query, it can use all of these tools.
I can’t add images in this post, but on the Marketplace webpage, there is an example how it works, and why it’s better than letting copilot search through the codebase.
Here’s the extension: https://marketplace.visualstudio.com/items?itemName=sehejjain.lsp-mcp-bridge
Here’s the source code: https://github.com/sehejjain/Language-Server-MCP-Bridge
Here are all the tools copilot can now use:
`lsp_definition` \- Find symbol definitions lsp\_definition
lsp_references \- Find all references to a symbol
`lsp_hover` \- Get symbol information and documentation
lsp_completion \- Get code completion suggestions
`lsp_workspace_symbols` \- Search symbols across the workspace
lsp_document_symbols \- Get document structure/outline
`lsp_rename_symbol` \- Preview symbol rename impact
lsp_code_actions \- Get available quick fixes and refactorings
`lsp_format_document` \- Preview document formatting
lsp_signature_help \- Get function signature and parameter help
https://redd.it/1nb2fib
@r_cpp
Preparation for interview
Hi guys, I'm 20(M). I am about to have an interview for an Intern C++ Developer position in about 2 days. This is my first interview related to C++ because I was working more with C# (Unity).
I want to ask if there are anything that I need to worry about? What are some of things that I need to practice before the interview? In some of bug fixing or performance fixes questions, what should I do while testing or finding the error?
Thanks for reply and sorry for my bad English =)
https://redd.it/1mx8om3
@r_cpp
A Post-Mortem on Optimizing a C++ Text Deduplication Engine for LLM: A 100x Speedup and 4 Hellish Bugs (OpenMP, AVX2, stringview, Unicode, Vector Database)
Hey r/cpp,
I wanted to share a story from a recent project that I thought this community might appreciate. I was tasked with speeding up a painfully slow Python script for deduplicating a massive text dataset for an ML project. The goal was to rewrite the core logic in C++ for a significant performance boost.
What I thought would be a straightforward project turned into a day-long, deep dive into some of the most classic (and painful) aspects of high-performance C++. I documented the whole journey, and I'm sharing it here in case the lessons I learned can help someone else.
The final C++ core (using OpenMP, Faiss, Abseil, and AVX2) is now **50-100x faster** than the original Python script and, more importantly, it's actually correct.
Here's a quick rundown of the four major bugs I had to fight:
**1. The "Fake Parallelism" Bug (OpenMP):** My first attempt with #pragma omp parallel for looked great on htop (all cores at 100%!), but it was barely faster. Turns out, a single global lock in the inner loop was forcing all my threads to form a polite, single-file line. **Lesson:** True parallelism requires lock-free designs (I switched to a thread-local storage pattern).
**2. The "Silent Corruption" Bug (AVX2 SIMD):** In my quest for speed, I wrote some AVX2 code to accelerate the SimHash signature generation. It was blazingly fast... at producing complete garbage. I used the \mm256_blendv_epi8 instruction, which blends based on 8-bit masks, when I needed to blend entire 32-bit integers based on their sign bit. A nightmare to debug because it fails silently. Lesson: Read the Intel Intrinsics Guide. Twice.
3. The "std::string_view Betrayal" Bug (Memory Safety): To avoid copies, I used std::string_view everywhere. I ended up with a classic case of returning views that pointed to temporary std::string objects created by substr. These views became dangling pointers to garbage memory, which later caused hard-to-trace Unicode errors when the data was passed back to Python. Lesson: string_view doesn't own data. You have to be paranoid about the lifetime of the underlying string, especially in complex data pipelines.
4. The "Unicode Murder" Bug (Algorithm vs. Data): After fixing everything else, I was still getting Unicode errors. The final culprit? My Content-Defined Chunking algorithm. It's a byte-stream algorithm, and it was happily slicing multi-byte UTF-8 characters right down the middle. Lesson: If your algorithm operates on bytes, you absolutely cannot assume it will respect character boundaries. A final UTF-8 sanitization pass was necessary.
I wrote a full, detailed post-mortem with code snippets and more context on my Medium blog. If you're into performance engineering or just enjoy a good debugging war story, I'd love for you to check it out:
conanhujinming/how-i-optimized-a-c-deduplication-engine-from-a-10x-to-a-100x-speedup-my-day-long-battle-with-4-5b10dd40e97b">**conanhujinming/how-i-optimized-a-c-deduplication-engine-from-a-10x-to-a-100x-speedup-my-day-long-battle-with-4-5b10dd40e97b" rel="nofollow">https://medium.com/@conanhujinming/how-i-optimized-a-c-deduplication-engine-from-a-10x-to-a-100x-speedup-my-day-long-battle-with-4-5b10dd40e97b**
I've also open-sourced the final tool:
GitHub Repo: https://github.com/conanhujinming/text\_dedup
Happy to answer any questions or discuss any of the techniques here!
https://redd.it/1mx00a5
@r_cpp
C++ with Boost in VSCode with CMake, Linux
Can someone please recommend a reasonably in-depth guide on setting up Boost to use in my C++ application in VSCode? Linux Mint, using CMake. Preferably for reasonably recent version, post-CMake 3.30 (where FindBoost was removed).
I can't make any absolutely minimal CMakeList.txt from any guides/tutorials to complete configure, once I add Boost dependency. CMake keeps giving me various errors (in find_package) and I am, as Google's Gemini would have put it, "at my wits' end".
Thank you in advance!
https://redd.it/1mwkm4v
@r_cpp
keeping .xdata while compiling for SUBSYSTEM:EFIAPPLICATION
i allready posted this on r/cpp\questions but i want to repost here bc ive heard that a msvc/stl dev is active here and i might get a better answer
copy pasted from the og post
im currently building the c++ runtime for my kernel (x64) and while working on supporting msvc exceptions i dscovered that the compiler doesnt emit the unwind data while compiling for efi applications.
this is a problem as i need to parse it for exceptions to work.
any ideas on how to solve this problem (sorry for bad spelling)
https://redd.it/1mw4l8t
@r_cpp
C++26: Concept and variable-template template-parameters
https://www.sandordargo.com/blog/2025/08/20/cpp26-P2841
https://redd.it/1mw27mz
@r_cpp
Which books would you guys recommend from this Humble Bundle?
https://www.humblebundle.com/books/ultimate-c-developer-masterclass-packt-books
https://redd.it/1mvs77q
@r_cpp
Which C++ library(s) are most similar to Python's Pandas or Polars?
https://redd.it/1mvnuii
@r_cpp
I forget how to code in c++
I studied at university, but during the summer vacation I forgot how to code :( I learned object-oriented programming "OOP" and even scored 56/60 in the final exam. But how could I forget coding after just two months without practice? It feels like I’ve lost almost everything I learned this year.
I tried not to start completely from zero, so I began working on small projects like building a simple calculator and added features such as while loops, cin.fail, and functions. From this, I realized I haven’t really forgotten; it’s just the nature of programming. It’s like math and other sciences: if you don’t practice, you start to forget.
I’m honestly tired, and I wanted to share this with you. It feels like I have to go back and restudy all the subjects I already learned.
https://redd.it/1mvkrwz
@r_cpp