-
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
Has there been any work to implement parts of std:: , e.g. std::pair using concepts?
Big promises of concepts were nicer error message, faster compile times.
You probably know that std:: implementations must support various c++ standards users might compile with so they can not always use latest language features.
But considering how big this improvements could potentially be I wonder if it would be worthwhile to do a preprocessor fork for preC++20 and C++20 standard.
For example this program:
std::pair<int, std::uniqueptr<double>> p;
std::pair<int, std::uniqueptr<double>> p2;
p2 = p;
https://godbolt.org/z/Pn8n87Ehz
In my opinion none of errors are good(I know people will comment that if I know what the problem is error makes sense...🙂), some are better than the others. I believe requires would give a better error.
Here is simple example of requires error(do not focus on the fact requires does not match above pair condition, it is just to show error).
https://godbolt.org/z/nhcj7Tvc8
Clang error is in my opinion amazing, it highlights the part of && that caused the failure.
Regarding compile time speed: no idea, but I believe std::pair is a good candidate for tests, since it is used in a ton of places in std, so it probably gets instantiated a lot during compilation in real codebases.
I think am not talking about any ABI breaking changes but not sure, I always forget how defaulting some member functions messes up ABI.
Before STL bans me for asking about this I want to say it was nice knowing you all. 😉
https://redd.it/1i927ye
@r_cpp
Jobs for a C++ programmer
I love C++ and the things you can do with this language. I have a lot of projects, but I don't work with C++. I don't want to quit my job because I'm afraid of being unemployed. I work as a web developer, but it's boring to me.
https://redd.it/1i8vbsj
@r_cpp
Seeking a Fast Data Structure for Random Searches with Keys and Multiple Values, Supporting 1 / 2 Billion Entries
Hello,
I am looking for a data structure capable of storing a key and a variable number of values associated with each key. The total number of keys could be around 1 to 2 billion. The search will be random. For example (this is just to demonstrate how the map is intended to be accessed, not to print the values):
map"one" = {1, 10, 1000, 100000}; // The Numbers could be 32 bit numbers unsigned
map"two" = {2, 20, 2000};
map"three" = {3, 30, 3000, 30001, 300002};
for (auto i : mapkey) {
cout << mapkeyi << endl;
}
I'm aware that unordered_map and map might be suitable choices, but I've read posts on a C++ forum mentioning that beyond a certain number of elements, the search complexity can become very high, and handling 1 to 2 billion elements might be problematic.
What would be the best option to achieve the behavior described above, where very fast search capability is the most critical requirement, followed by memory efficiency?
Thank you!
https://redd.it/1i8siq1
@r_cpp
How do you stay up-to-date with the latest C++ standards? Any favorite resources?
https://redd.it/1i8peno
@r_cpp
Aliasing Hardware Registers with a C++ Class Without Allocating Memory
Hello everyone!
I am trying to create a class to abstract GPIO functionality for some MCU. My goal is to alias the GPIO_BASE address using a class such that GPIO directly maps to the hardware register. Essentially, I want GPIO to act as a "placement" for the GPIO_BASE address without allocating any additional memory for the object.
Here is the code snippet I came up with:class GPIO_Type { public:
void *operator new(size_t)
{ return reinterpret_cast<void *>(GPIO_BASE);
} }; //... GPIO_Type &GPIO = *new GPIO_Type;
I am using arm-none-eabi-g++ with the -O0 flag for now, but I plan to experiment with compiler optimizations later. However, my general question is: Is this approach even possible in C++ (without occupation of additional memory)?
I would appreciate any advice or alternative approaches to achieve this while ensuring no memory allocation occurs.
https://redd.it/1i8d2ln
@r_cpp
Benefits of static_cast
I'm primarily a C developer but my current team uses C++. I know that C++ has several types of casts (e.g., `static_cast`, `dynamic_cast`). What are the benefits of using `static_cast` over a C-style cast (i.e., `(Foo*)ptr`)?
https://redd.it/1i85uv5
@r_cpp
How effective is ctags?
In C they're effective for navigating large projects. In C++ anyone use it?
https://redd.it/1i84tc3
@r_cpp
Building a dynamic memory allocator.
The title explains it pretty much, I'm currently a 3rd year CSE student. I recently got into low level stuff as I don't like web dev. I thought of building a custom allocator in c++ to improve my c++ skills and help me understand the inner workings.I use c++ for leetcode and it's been a while since I've worked with OOPs part of it. I want to build this without gpt and only referring to Google as much as possible. Maybe I'm foolish in trying this but I want to be able to do it without relying heavily on AI. What are some things I should read before starting and some tips on how to work on the project. If there are better projects to do instead of this, I'm open to those and constructive criticism as well. Thanks a lot
https://redd.it/1i7yl26
@r_cpp
Breaking the cycle
Hello everyone
I'm not sure if this is the right place to ask. But I am seeking advice on how to break out of this perpetual cycle of relearning C++, learning the basics, the data structures, writing simple programs, and then throwing it all away again. I have graduated from college about a year and a half ago with a degree in Computer Science. Currently 25 and unemployed. My situation is starting to cripple me so much that I feel so inadequate and unsatisfied with my current self, and that if I continue living this way, nothing will change.
So now, I really want to keep myself determined. Whenever I start this cycle, I usually do it blindly on my own and then end up burning myself out. Today I finally decided write this post and seek advice rather than just pushing myself to try it out again and again. I want to hear other people's opinions, people who may have gone through the same situation as I am. I would love to hear your advice and/or stories on how you broke out of this slump. How did you do it? Any sites that helped you? Books? People? Things you did for yourself? Your day-to-day schedule to prevent burnout? Self-imposed habits? Anything that would help, really.
I really want to change my mindset with these sort of things and keep myself disciplined. I want to go past writing simple programs and having the grit to continue rather then repeat over and over again. I do enjoy coding, and C++ was my first programming language, while I also delved on Java and Python during my time in college, I would love to stick with one language and C++ is my choice, as difficult as it is.
As of now I use these materials whenever I try to relearn C++
First of which is the https://www.learncpp.com/ website, and
Second being the C++ Programming Program Design including Data Structures Book by D.S. Malik that I had during college
I would also look back to my old programs I wrote when I was still studying.
I also tried learning sites like https://www.codecademy.com/ and https://www.hackerrank.com/ specifically for C++ problem questions
I'm not sure as to how effective and relevant they are or if they even still are worth using. I would love to hear other's thoughts about it.
But that's basically all there is for me to say and share. Just someone who aspires to be a disciplined programmer and break out of this cycle. I would deeply appreciate all the help I could get.
https://redd.it/1i7yrmf
@r_cpp
What features would you like to see in future C++ standards to make the language even more powerful or user-friendly?
https://redd.it/1i7w7gf
@r_cpp
C++ programmer′s guide to undefined behavior: part 12 of 11
https://pvs-studio.com/en/blog/posts/cpp/1211/
https://redd.it/1i7ppjb
@r_cpp
Domain knowledge
Hello all,
I applied c++ in many areas: finance, robotics, automotive and networking. Used memory management, multithreading, api design and networking. Is this a good knowledge base? Do i lack domain knowledge?
I dont want to program so much anymore. I want to design and write the requirements. But i dont have the domain knowledge. I will start working on video streaming, still coding.
How can i go to the next level?
https://redd.it/1i7jvfr
@r_cpp
Jonas Norberg: Ghidra saves the day
https://youtu.be/iKWqwdeYR60
https://redd.it/1i7igmm
@r_cpp
snake game programming
my first project in sem 2 is snake game programming so far we have been taught c/c++ and dsa is currently going on and i have absolutely no idea how to do these project so i just wanted to know how everybody does projects , do you do everthing on your own or some or 50% yt help or some help from ai and also c/c++ is enough right?
https://redd.it/1i7f46e
@r_cpp
Are there any active proposals w.r.t destructive moves?
I think destructive moves by themselves are amazing even if we can not have Safe C++.
For people not familiar with destructive moves [safe cpp](https://safecpp.org/draft.html) has a nice introduction.
We address the type safety problem by overhauling the object model.
Safe C++ features a new kind of move: relocation, also called destructive move.
The object model is called an affine or a linear type system.
Unless explicitly initialized, objects start out uninitialized.
They can’t be used in this state.
When you assign to an object, it becomes initialized.
When you relocate from an object, its value is moved and
it’s reset to uninitialized.
If you relocate from an object inside control flow,
it becomes potentially uninitialized, and its destructor is
conditionally executed after reading a compiler-generated drop flag.
std2::box is our version of unique_ptr. It has no null state. There’s no default constructor.
Dereference it without risk of undefined behavior. If this design is so much safer,
why doesn’t C++ simply introduce its own fixed unique_ptr without a null state?
Blame C++11 move semantics.
How do you move objects around in C++? Use std::move to select the move constructor.
That moves data out of the old object, leaving it in a default state.
For smart pointers, that’s the null state.
If unique_ptr didn’t have a null state, it couldn’t be moved in C++.
This affine type system implements moves with relocation. That’s type safe.
Standard C++’s object model implements moves with move construction. That’s unsafe.
https://redd.it/1i7ab14
@r_cpp
Interview questions at Hft firms for c++ roles
Hi all,
I was wondering what kind of interview questions and topics you’d receive now in 2025 when interviewing for a low latency C++ engineer at a high frequency trading firm and how you can best prepare for it? (think Optiver, Jump, Radix, HRT, Headlands, IMC, DRW etc). Is there also a difference between Europe Vs US? As I am based in the Netherlands and looking to move to low latency developing. All insights are appreciated.
https://redd.it/1i8zct5
@r_cpp
C pitch for a dialect directive
I just saw the pitch for the addition of a #dialect directive to C (N3407), and was curious what people here thought of the implications for C++ if something like it got accepted.
The tldr is that you'd be able to specify at the top of a file what language version/dialect you were using, making it easier to opt into new language features, and making it easier for old things to be deprecated.
I've thought for quite some time that C++ could do with something similar, as it could mean we could one day address the 'all-of-the-defaults-are-wrong' issues that accumulate in a language over time.
It may also make cross-language situations easier, like if something like clang added support for carbon or a cpp2 syntax, you could simply specify that at the top of your file and not have to change the rest of your build systems.
I hope it's something that gains traction because it would really help the languages evolve without simply becoming more bloated.
https://redd.it/1i8udz2
@r_cpp
Hiding x86 Port Latency for 500 GB/s/core Reductions 🫣
https://ashvardanian.com/posts/cpu-ports/
https://redd.it/1i8sepy
@r_cpp
Sandor Dargo's Blog: C++26: pack indexing
https://www.sandordargo.com/blog/2025/01/22/cpp26-pack-indexing
https://redd.it/1i8plnn
@r_cpp
Must-know libraries/frameworks/technologies for C++ developer as of 2025
As a junior C++ dev now I use mostly pure C++. But I'd like to know what are some primary technologies should be learned to stay relevant on the job market and be able to switch domains. Some of them I believe are obviously necessary are boost, Qt, CMake, gtest (or any other unit test library).
Would be cool to hear about technologies used by C++ devs at FAANG companies.
Or maybe I'm wrong and core C++, DSA and STL are enough for good C++ position?
https://redd.it/1i8a5lm
@r_cpp
Microsoft released Proxy 3.2
https://github.com/microsoft/proxy/releases/tag/3.2.0
From the release notes, it seems that RTTI, std::format and borrowing semantics has been implemented in this release, while the benchmarking also looks competitive.
https://redd.it/1i85tff
@r_cpp
How frivolous use of polymorphic allocators can imbitter your life
https://pvs-studio.com/en/blog/posts/cpp/1212/
https://redd.it/1i83iig
@r_cpp
BlueHat 2024: Pointer Problems – Why We’re Refactoring the Windows Kernel
A session done by the Windows kernel team at BlueHat 2024 security conference organised by Microsoft Security Response Center, regarding the usual problems with compiler optimizations in kernel space.
> The Windows kernel ecosystem is facing security and correctness challenges in the face of modern compiler optimizations. These challenges are no longer possible to ignore, nor are they feasible to mitigate with additional compiler features. The only way forward is large-scale refactoring of over 10,000 unique code locations encompassing the kernel and many drivers.
Video: https://www.youtube.com/watch?v=-3jxVIFGuQw
https://redd.it/1i7y4ru
@r_cpp
Sublime fatal error: 'iostream' file not found on Mac running C++ program (x-posted on r/Sublime)
I'm in a computer science foundations class learning C and C++. my c files run fine in sublime with command B but my c++ file is returning "fatal error: 'iostream' file not found". I think I have to reset a path? But I don't really understand how to do that.
Please help!
This is the full error:
/Users/victoria/Desktop/CSF/Workshops/studentList.cpp:3:10: fatal error: 'iostream' file not found
3 | #include <iostream>
| \^\~\~\~\~\~\~\~\~\~
1 error generated.
[Finished in 199ms with exit code 1\]
[shell_cmd: gcc "/Users/victoria/Desktop/CSF/Workshops/studentList.cpp" -o "/Users/victoria/Desktop/CSF/Workshops/studentList" && "/Users/victoria/Desktop/CSF/Workshops/studentList"\]
[dir: /Users/victoria/Desktop/CSF/Workshops\]
[path: /opt/local/bin:/opt/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin\]
https://redd.it/1i7xxv0
@r_cpp
Using Polymorphic Allocators and Policy-Oriented Design for a Reside-Anywhere Singleton
Hi, Folks. rekerner/c-17-reside-anywhere-singleton-with-polymorphic-allocators-130860eb345f">This blog post demonstrates how to use the "new" c++17 polymorphic allocators to implement a singleton (or any other design component) such that it uses a configurable policy to determine where to instantiate an object, whether it's on the stack, the heap, in program memory, shared memory, file-mapped memory or GPU-mapped memory, without modifying original, legacy implementation.
I believe it presents an important aspect of extensibility design consideration-- making sure an architectural feature addresses its domain of concern and nothing more.
https://redd.it/1i7qasd
@r_cpp
Memory safety and network security
https://tempesta-tech.com/blog/memory-safety-and-network-security/
https://redd.it/1i7oglp
@r_cpp
Resource Acquisition Is Initialization
https://debdebnath.com/posts/raii
https://redd.it/1i7knyy
@r_cpp
Project Ideas?
I'm a beginner in C++ (I've already done intermediate projects but I think I should first strengthen my base).
My last project was an "Ecosystem Simulator", the code worked but it was a botch job, I'm now reading Clean Code and I want ideas for a project.
https://redd.it/1i7gktn
@r_cpp
multiple (virtual) implementations of SPIClass.transfer() method
ok this isn't 'stackoverflow', but nevertheless I hit a bummer writing some codes. Hope I'd get some help here.
I'm writing up an implation of Arduino SPIClass that interface STM HAL for SPI.
As I'm implementing SPI with DMA across the various stm32 series(es)
I hit a bummer in that the SPI hardware is different between 2 series, hence, the include headers has different definitions, and during a build, I hit a symbol not found error in the implementation and have had to place some ugly if-defs for the SPI.transfer(byte c) method
https://github.com/ag88/stm32duino\_spi\_dma/blob/main/src/SPI/SPIDMA.h#L37
https://github.com/ag88/stm32duino\_spi\_dma/blob/main/src/SPI/SPIDMA.cpp#L206
so it happens that for some of the stm32 series, the default code works.
but that there are other stm32 microcontrollers that has a little different (better) hardware but the include definitions are different and hence I need to write a new implementation.
I'm writing an if-def so that if it is the defacto implementation that works, it is impmenented.
else i make that a pure virtual function so that the derived class has to implement that.
is there a better way to do this?
Thanks in advance.
https://redd.it/1i7blog
@r_cpp
SDL3 is officially released! It's version 3.2.0 stable.
https://www.patreon.com/posts/sdl3-is-released-120491416
https://redd.it/1i7as3w
@r_cpp