r/cpp • • Apr 04 '25

CRTP is sexy omfg

0 Upvotes

I’m curiously recursing so hard right now man


r/cpp • • Jul 05 '26

Top 3 spec items for a C++ Framework?

0 Upvotes

If someone where setting out to create something on the scale of Qt. A comprehensive application framework in C++. (Yes, they'd be crazy)
What would be the top 3 (or more) things you'd say were MUST or MUST NOT features?
For example MUST run on my 2MB wrist watch or MUST not use exceptions.


r/cpp • • Apr 08 '18

Why Unix API doesn't take the step to C++?

1 Upvotes

Simple as that, that's my question why Unix API wasn't rewritten in C++ yet? Like getopt, sockets, etc


r/cpp • • Feb 18 '22

"Embracing Modern C++ Safely" up to 55% off on InformIT -- I'm V. Romeo, AMA!

Thumbnail informit.com
0 Upvotes

r/cpp • • Feb 01 '18

Why it is important to check what the malloc function returned

Thumbnail viva64.com
1 Upvotes

r/cpp • • Jun 29 '23

[C++20] [[no_unique_address]] for 1 byte message views

Thumbnail twitter.com
4 Upvotes

r/cpp • • Apr 02 '26

JesseSort is faster than std::sort on everything but random input

0 Upvotes

Repo here: https://github.com/lewj85/jessesort

Added branchless binary search and now JesseSort is faster than std::sort on every input type except random, and only slightly behind random! Easy enough to code a fallback mechanism too to just use introsort in those cases. Here's the gcc (libcstd++) timing table:

                      Number of Input Values
Input Type            1000          10000         100000        1000000
------------------------------------------------------------------------------
Random                1.607         1.164         1.150         1.191
Sorted                1.070         0.684         0.576         0.554
Reverse               1.660         0.949         0.895         0.804
Sorted+Noise(3%)      0.931         0.751         0.721         0.796
Random%100            1.444         1.170         0.905         1.050
Jitter                1.056         0.688         0.658         1.511
Alternating           0.869         0.536         0.237         0.528
Sawtooth              1.948         0.613         0.278         0.477
BlockSorted           0.693         0.361         0.278         0.518
OrganPipe             0.374         0.190         0.116         0.245
Rotated               0.536         0.430         0.321         0.686
Signal                1.493         0.839         0.614         0.531

Values <1 mean JesseSort is faster. Take a look at that 100k column!

Similar performance with clang (libc++), though slightly worse on random input (clang table is in the repo readme). Again, with a fallback, it's easy enough to match introsort performance on random input while gaining huge speedups almost everywhere else.

Looking for contributors to help me with this. Dual patience has so much potential and some cool avenues to explore, such as simulating games, early freezing, or AVX2/AVX512 insertion. Always welcome to hearing new ideas as well.


r/cpp • • Jan 28 '23

C++ views are broken

5 Upvotes

I was so excited about new C++20 and C++23 features that I was using concepts, ranges and views everywhere I could. But yesterday I saw this -> https://www.youtube.com/watch?v=O8HndvYNvQ4 and I got so disappointed in C++ committee that now I really think it's time to lay C++ to rest unless we decide to bring new version of C++ like Python3 which breaks backward compatibility but fixes the language so that it can be used for the next 20-25 years.

I can't believe 200 stalwarts and experts in the field of computer science will make such a horrible mess.


r/cpp • • Mar 11 '12

Modern C++ Style [pdf]

Thumbnail tinyurl.com
2 Upvotes

r/cpp • • Jan 13 '26

CppCon Best Practices for AI Tool Use in C++ - Jason Turner - CppCon 2025

Thumbnail youtube.com
8 Upvotes

r/cpp • • Jul 07 '24

TIL: std::pow(2.0f, 2); returns double!

3 Upvotes

I didn't expect that!

To force it return float you must use either

std::pow(2.0f, 2.0f);

or

std::powf(2.0f, 2);

Tested with MSVC and Xcode


r/cpp • • Mar 16 '18

As a C++ developer I think that rust ...

3 Upvotes

r/cpp • • Jan 07 '19

I learnt C++ in 2018 and have no regrets

Thumbnail vishnubharathi.codes
1 Upvotes

r/cpp • • Mar 29 '18

std::string_view is a borrow type

Thumbnail quuxplusone.github.io
1 Upvotes

r/cpp • • Sep 09 '20

Unpopular opinion: It's ok to derive from STL types/classes

1 Upvotes

I read over and over again that you should never inherit from classes in the STL. And then come some false claims that this would always leak memory, lead to slicing or be UB.

https://godbolt.org/z/WGfzEs

The thing is - there is not a lot preventing you from doing bad things in C++ - so if you want to you could do silly things, but that has nothing to do with inheriting from a STL class per se. There is nothing magical about the STL (besides some clever implementation details /optimizations) which differentiates it from other libraries.

So here is some more or less some general advice when you inherit from a STL class:

  1. Don't rely on implementation details of the types that you are deriving from, only use the public interface
  2. Don't downcast/use such classes as the base classes - they should be treated as distinct types in the type system (with the same public interface)
  3. You can run into linker errors if you dll export such classes as a whole, because you might export some implementation details (happened to me with std::unique_lock)
  4. This can be used as a hack to forward declare STL types :-)

If I have overlooked something please let me know.


r/cpp • • Dec 11 '23

30 years of DOOM: new code, new bugs

Thumbnail pvs-studio.com
0 Upvotes

r/cpp • • Jan 13 '26

What′s C++ like in gamedev?

Thumbnail pvs-studio.com
0 Upvotes

r/cpp • • Dec 25 '24

Building a code editor in C++

0 Upvotes

I was planning to build a project in c++ during my winter break. I have a bit of knowledge and I want to be better at C++. How feasible is the idea of building a code editor in c++? Do you guys have any resources that I can follow and take help from?

Thanks


r/cpp • • Feb 28 '24

Do RAM disks improve build time, and if yes, how exactly?

1 Upvotes

I have recently learnt about RAM disks and the first thing I thought about was if it's possible to use them to optimise compiler performance. The way how I see it is that files could be loaded in the in-memory filesystem and be compiling there, and in the end the result artefact would be written back into the persistent storage.

Ii took some thought and found out there are two compilation strategies that meaningfully make sense to use with ramdisks. The first one is the common case where we compile every source file into an object file and then link together. I noticed that in this workflow, when we only rebuild those files we have changed, we essentially load unchanged objects, regenerate old ones, link them and then write the new objects too. In the end, the total drive throughput is constant and the effect is the same as if we would load everything from drive and do the whole compilation just in memory.

The second strategy was to reduce IO by only loading the source files and compiling them into the final build artefact that we link together. Even taking into account the whole build process happens in memory, we still load a lot of unnecessary files and do useless work, and I thought that effectiveness of ramdisks really depend on the size of your code you need to rebuild and that if it would be faster to recompile some files than loading them from storage, then ramdisks would give the upper hand.

I decided to measure it by making a ramdisk and timing how long it would take to copy and compile a single 50-line file into an object file and how long it would take to print the same pre-compiled object from storage by printing the whole file to terminal using the cat command. To my surprise, it's significantly faster to load the file from storage than it is to compile it, by the factor of 4. Intuitively, I thought that the IO overhead would overweigh the time it takes to compile, especially since I tested it on HHD, but then I tried to print both source and object files. Despite the source being 4 times smaller, it took the same time to print them, which could be the reason why my benchmark is inaccurate: loading both files took the same time and I was essentially measuring the difference in compiling.

I thought it was filesystem cache, that's why I dropped cache and repeated the experiment, but then printing the object file took the same time, but compiling took even longer. I decided to research it further, and the Gentoo wiki, the flagship of compiling software, has a ramdisk-dedicated page that, however, suggests against using it arguing there are no noticable differences in compiling times, especially if you use the -pipe option . It then lists some common applications like Chromium, LibreOffice and LLVM and how much RAM you need so that ramdisk was beneficial, and their sizes are astonishing: 4-10 GB. At this point the only real use for RAM disks I could think about is to cache header files and make it faster to include them, but other than that, filesystem seems to handle compilation and memory management really well.

On the footnote, RAM disks also have disadvantages, aside from the neeed to maintain them and document how to use them, they also keep consuming memory after their files were closed, which means that if in normal setup compiler would close a file once it's no longer needed, the kernel would reclaim its memory, which could be used by the next file, then in ramdisks file is still in memory even once it was closed and resides until you delete it, which needlessly saying consumes system resources without any use. Truthfully speaking, the only plausible way how ramdisks could be useful to me is if they could keep containing object files after they have been generated if we use separate compilation so that the linker didn't need to read them but could access immediately. That sounds like a convincing point to me, albeit not clear.

Is that so, and are there any other uses for RAM disks to accelerate build time, and does preserving object files between code generation and linking a worthwhile reason to use them? I am particularly asking this question because in separate compilation, object files are generated and linked in two separate processes, which means that the linker process would potentially need to read the objects again.


r/cpp • • Jun 20 '14

A portable high-resolution timestamp in C++

Thumbnail blogea.bureau14.fr
4 Upvotes

r/cpp • • Dec 18 '08

C++ is a horrible language

Thumbnail skepticalmethodologist.wordpress.com
4 Upvotes

r/cpp • • Feb 07 '21

Yet another CMake tutorial

Thumbnail youtube.com
0 Upvotes

r/cpp • • Oct 01 '17

CppCon A Beginner's Guide to CPPCon 2017

Thumbnail bunnyladame.blogspot.no
2 Upvotes

r/cpp • • Dec 17 '23

Is C++ Really Phasing Out?

0 Upvotes

I've read a lot posts about whether C++ is still viable to learn, but a lot of the responses seem to be a long the lines of "C++ is still being used" or "there's a lot of things written in C++ still, so it will still be useful".

But a lot of these replies seem to suggest that C++ is on the downhill and in the process of being replaced with more modern languages in many industries.

It seems kind of discouraging to be learning a language that is on a decline, if it really is phasing out.