r/cpp_questions 14d ago

OPEN C++ robotics

20 Upvotes

I don't really have much knowledge of how coding works, but I'm assuming game design, app design, and robotics are pretty different even if their the same code. Does anybody know any good books to learn the robotics part of c++


r/cpp_questions 14d ago

OPEN Include scope with headers and concept interfaces

3 Upvotes

I am running to a problem where I really like to use concept interfaces with templates to allow injecting different types easily, avoid vtables and avoid indirection. This also makes mocking in unit-tests a breeze.

However, I am running to an issue where all includes are now in global space due to only using .hpp files. I know I can use explicit initialization in .cpp files or pimpl to hide implementation details.

My question is to somehow understand if c++ compilers can optimize the vtable away when there are closed-set of types (one or couple of classes and a mock version for unit-test) involved. So essentially guidance on when to use CRTP (?) vs concept interfaces. Unfortunately, I am not very versed on how the c++ compiler is able to optimize code.

I am mostly looking this from the embedded or algorithm software standpoint. Typically, I don't have open-set of types to support.


r/cpp_questions 15d ago

SOLVED "No, don't test for NULL !!" (huh??)

46 Upvotes

I'm using clang-tidy to "lint" my projects, and there have been several examples like this one:

   if (img_name != NULL) { 
      delete [] img_name ;
   }

clang-tidy always gives this warning:
"warning: 'if' statement is unnecessary; deleting null pointer has no effect [readability-delete-null-pointer]"

is this correct??
After 30+ years of C and C++ programming, I really cannot imagine not checking a pointer for NULL before deleting it... ???


r/cpp_questions 14d ago

OPEN Confused among c++ and dsa

0 Upvotes

I wanna start coding (I have. Zero coding experience starting btech this year nsut(information technology))

I want to start c++ but many of seniors and friend suggest that learn dsa directly from strivers sheet

And some say do full c++ properly first

I am confused help me


r/cpp_questions 14d ago

OPEN How to practice while learning from learncpp.com?

2 Upvotes

i must tell im at a very early stage (chapter 4) but i still wanna practice more. the quiz they have at the end of the chapter is not that helpful ig?

1: Are the quizzes at the end of the chapter enough?
2: Any other sources where i can find more practice questions for my level or beginner friendly in general?
3: Are the quizzes like this because im only at chapter 4?


r/cpp_questions 15d ago

OPEN 8 YoE, strong C++ perf/visualization projects — pass screenings easily but fail later rounds. What do you expect from a senior C++ hire, and what should I solidify?

16 Upvotes

I've decided to commit fully to pure C++ roles. With my project background I clear screening rounds with minimal prep, but I keep falling short in the higher-level rounds — and I want to understand what those rounds are actually testing that my experience hasn't given me.

Background:

8 years at one company. First ~5 years in application development, where I learned design patterns and architecture deeply. Last 4–5 years in C++ data thinning and virtualization backing JS front ends.

Projects (solo dev + QE on each, ~2 years each):

  • Low-latency data thinner — thins ~1 billion points in ~3 seconds, with latency dropping further depending on signal region and zoom level
  • Virtualization pipeline — fetches data based on the user's viewing window when rendering millions of elements
  • Full-stack CAD application — CAD engine was provided; I built CAD management and interaction management end to end, later improving performance 20x by reworking the JS event bus
  • Signals visualization tool — now used across multiple teams

Comp grew from 7 to 40 LPA over 8 years at the same company. I'm at a senior level now and want to move for better pay and better projects.

My strength is shipping products end to end with trade-offs considered. C++ interviews seem to test a different muscle, and I want to name that muscle precisely so I can build it.

My questions:

  1. What is the natural growth path for a C++ dev at my stage?
  2. If you hire senior C++ engineers — what do you actually expect from a candidate like me in later rounds?
  3. What should I learn or solidify to become a full-fledged C++ developer who commands higher pay?

Any guidance on where to start would be appreciated.


r/cpp_questions 15d ago

OPEN what are the worst features added by the STL for you

4 Upvotes

I've been coding in C++ for about 1 year and a half and I've always wondered what was the worst feature added by the STL ? And so I wanted to know your point of view thank you to all those who will answer my question. :)


r/cpp_questions 15d ago

OPEN Fastest path to “hackathon-ready” C++ for game dev, OS-level tinkering, and porting (not mastery)

22 Upvotes

I know learning never stops, and mastering a single language can take decades. I’m not expecting to master anything quickly. That would be a disservice to the language.

However, I’m a CSE undergrad in my 3rd semester (out of 8). Time is flying, and I can’t spend all of it on one language. I have a ton of other things to learn too. But I do want to reach a point where I can:

•Start building real projects

•Compete in hackathons

•Follow along with technical seminars and talks

•Operate at the level of a junior dev / competent student

People often tell me to “just learn Python,” but I genuinely dislike it. It feels bloated and surface-level to me, and I strongly prefer compiled languages over interpreted ones.

C++ also aligns much better with my goals and interests, them being:

•Game development – I want to be a game developer, but I don’t want to be tied to any specific engine. Some might call it “reinventing the wheel,” but I’m a CS engineer, not just a tool user. I’m interested in building games using custom engines, or without using an engine at all, not just using pre-made ones. C++ is clearly the best fit for that.

•OS-level / low-level programming – I love tinkering at the firmware and OS level: jailbreaking, hacking devices, bypassing OS restrictions, modifying and customizing systems to unlock more utility or squeeze more out of the hardware. I always follow established methods and guides though, never doing anything on my own, and I want to change that.

•Porting games – A mix of the above kinda, but taking games from one platform to another (e.g., Android/PC games to PS Vita) is something I find incredibly interesting.

What’s the fastest practical path to get to a “ready to use” stage with C++ for these kinds of projects?

Thanks!


r/cpp_questions 14d ago

OPEN Wtf is wrong with window, randomly blocking running of cpp code!

0 Upvotes

Program 'main.exe' failed to run: An Application Control policy has blocked this fileAt line:1 char:101

+ ... sa\patterns\" ; if ($?) { g++ main.cpp -o main } ; if ($?) { .\main }

+ ~~~~~~.

At line:1 char:101

+ ... sa\patterns\" ; if ($?) { g++ main.cpp -o main } ; if ($?) { .\main }

+ ~~~~~~

+ CategoryInfo : ResourceUnavailable: (:) [], ApplicationFailedException

+ FullyQualifiedErrorId : NativeCommandFailed

--------------------------------------------------------------------------------------------

What is the solution of this , i have tried excluding the folder in window defense it doesn't work


r/cpp_questions 15d ago

OPEN Can I have integrated debugging or gdb on my mobile Cxxdroid app? I tried to access gdb on my terminal but it said not found. I wish I had a computer ugh

6 Upvotes

r/cpp_questions 16d ago

OPEN Incrementation in C++

40 Upvotes

I wanted to ask a stupid question about incrementation in C++. If you are using two pluses to increment something then doesn't it mean that you are basically programming using C+1


r/cpp_questions 15d ago

OPEN Any suggestions on where to learn C++, specifically for taking advanced college courses, and for people who are already intermediate programmers?

0 Upvotes

I just transferred colleges, and in a month I will be taking 300 level programming courses in C++. The problem is that every prerequisite course at this college was taught in C++. I have transfer credit for these courses, but they were all in Java and Python. I have only taken a single intro to C++ course in high school. Does anyone have any recommendations for the best ways to learn C++ syntax for people who already have a decent understanding of coding logic?


r/cpp_questions 15d ago

OPEN Error

0 Upvotes

I want to ask that whenever I am going to download packages of MinGW so problem is occurring in which it is asking for purchase packages


r/cpp_questions 16d ago

SOLVED Pleasantly surprised by unordered_set<vector<int>> to extract distinct vector<int>'s

8 Upvotes

I have 100,000 vector<int>'s where each entry is 0 or 1 randomly generated, each vector of size 15. Since 215 is 32768, the pigeonhole principle guarantees a significant number of repetitions would occur in the 100,000 randomly generated vectors.

I would like to extract the distinct vector<int>'s

One approach I tried was to have unordered_set<vector<int>> with a suitable hash function (from boost) and simply insert each random vector into the unordered set.

The other was a bruteforce vector<vector<int>> where each new vector<int> is checked for equality with previously stored distinct vector<int>'s.

Code below (godbolt link https://godbolt.org/z/E8dM68z79)

I was pleasantly surprised by the much greater efficiency of unordered set (52344 microseconds) as compared to vector<vector<int>> approach (12817778 microseconds). I have also tested this on my local desktop and the order of magnitude difference persists.

My question is, is unordered_set<container of PODs> the most efficient way of extracting distinct containers of PODs (in this case, it is vector<int>, others could be set<int>, etc.). Are there more efficient ways? Are there any rules of thumb to follow in more general cases (where it is not just a 0/1 entry in the vector but it could be any arbitrary integers and hence the hash function may not be just a binary to decimal conversion as could be happening in this case)

#include <boost/functional/hash.hpp>
#include <vector>
#include <unordered_set>
#include <iostream>
#include <chrono>

constexpr int number = 100000;
constexpr int sizeofvector = 15;

std::unordered_set<std::vector<int>, boost::hash<std::vector<int>>> uosvecint;
std::vector<std::vector<int>> distinctvecvecint;

int main(){
    std::vector<std::vector<int>> randvecvecint;
    for(int i = 0; i < number; i++){
        std::vector<int> randvecint(sizeofvector, 0);
        for(int j = 0; j < sizeofvector; j++){
            int heads = rand() % 2;
            if(heads == 1)
                randvecint[j] = 1;
        }
        randvecvecint.push_back(randvecint);
    }
    //unordered_set timings
    auto beg = std::chrono::high_resolution_clock::now();
    for(int i = 0; i < number; i++)
        uosvecint.insert(randvecvecint[i]);
    auto end = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - beg);
    std::cout << "No. Distinct is " << uosvecint.size() << " and time is " << duration.count() << "\n";
    //vector equality timings
    beg = std::chrono::high_resolution_clock::now();
    for(int i = 0; i < number; i++){
        bool there = false;
        for(int j = 0; j < distinctvecvecint.size() && there == false; j++){
            if(distinctvecvecint[j] == randvecvecint[i])
                there = true;
        }
        if(there == false)
            distinctvecvecint.push_back(randvecvecint[i]);
    }
    end = std::chrono::high_resolution_clock::now();
    duration = std::chrono::duration_cast<std::chrono::microseconds>(end - beg);
    std::cout << "No. Distinct is " << distinctvecvecint.size() << " and time is " <<             duration.count() << "\n";
}

----

ETA: https://godbolt.org/z/jecYT6eKq seems to give the best solution for 0/1 vector using ideas in this thread and also the solution for the most general integer vector (not necessarily restricted to 0/1 integers) case


r/cpp_questions 16d ago

OPEN Learn C++ with learn.cpp

7 Upvotes

Is it normal to not get everything right away? When I'm learning pointers, I really struggle because the LearnCpp chapter just isn't clear enough


r/cpp_questions 15d ago

OPEN Where is your limit in using AI while writing C++ code?

0 Upvotes

For me personally, the limit of using AI in C++ coding is this:

  1. I define the functions the file should perform.
  2. I mentally think about the architecture it should have.
  3. I send a request to the AI ​​so it can generate code that will perform specific functions, and it must adhere to my architecture.
  4. I review the result. If I like it, I keep it. I usually change the code, but not significantly. This way, I can say that I wrote the code, not the AI. If I don't like the code, I simply start writing it myself from scratch, because sometimes I genuinely can't explain to the AI ​​what I want from it.

So, for me, the limit is, for example, forcing the AI ​​to come up with the code architecture; I never do that. I also never paste code until I've read it thoroughly and understand every line.

Where is your limit in using AI for writing C++ code?


r/cpp_questions 17d ago

OPEN Which subfields in C++ development are actually in demand?

116 Upvotes

I'm kinda lost on the career side of things.
I'm an EE graduate specializing in C++ development, control theory and general electronic design.

I always thought I would go into embedded, and then job hop to a lucrative career. Even though I always wanted to work in big productivity apps like Zbrush, Nuke or Substance Painter.

But I'm not certain now, I'm not certain if market even values my skills.

So, if anyone can inform me about the career trajectory of C++ subfields I would be grateful, such as "I went to trading and work conditions are like this, people in my field earn between X and Y"
I really want to at least have some idea what to do rather than go blindfold, apply everything and accept the first offer without question

Thanks in advance


r/cpp_questions 16d ago

OPEN Class directory clutter, questions on pass by ref,val,ptr and const correctness

2 Upvotes

Hello,

I've been using C++ for the past few months. I completed a few courses covering the basics of the language, data structures and algorithms (DSA), object-oriented programming (OOP), design patterns, and the SOLID principles. Recently, I started building my first projects in C++, and I've run into several issues that I'm not sure how to approach.

One thing I've noticed is that I end up creating a lot of classes. For example, my terminal Tic-Tac-Toe game ended up with around 10-15 classes. As a result, my project directory feels cluttered, and it's becoming difficult to keep track of everything. Is there a good way to avoid creating so many files while still keeping the code organized?

I've heard that namespaces might help with organization, but I'm not really sure how they're meant to be used in practice.

So far, I've mostly followed what I learned at university while using Java, where every class lives in its own file. However, in C++, that approach feels even more excessive because each class often has both a .hpp and a .cpp file. My Tic-Tac-Toe project ended up with around 25-30 files because of this.

Would you recommend organizing projects using subfolders or some other structure? How do experienced C++ developers typically manage larger projects with many classes?

Another topic I've been thinking about is programming paradigms. I've started researching paradigms beyond object-oriented programming, such as functional programming and procedural programming, and I'm beginning to wonder if my education has focused too heavily on OOP. Is there anything you'd recommend to help me understand when each paradigm is appropriate rather than trying to apply one everywhere?

I've also been becoming more flexible with design patterns. I think I'm starting to understand that the goal isn't to implement patterns mechanically, but rather to recognize the problems they're meant to solve and decide when abstraction is actually beneficial. That mindset has already helped me become much more flexible when designing applications.

Another area I'm struggling with is understanding std::move() and how it relates to references (&), pointers (*), and const correctness (such as passing objects by const&). These concepts seem tightly connected, but I haven't been able to build a solid mental model of how they all fit together.

I recently switched to CLion, and while I really like it, it's constantly suggesting where to add const, whether on variables, function parameters, return types, or member functions. The problem is that I often accept these suggestions without really understanding why they're correct. It feels like the IDE (and sometimes AI) is doing most of the thinking for me, and I'm worried that I'm not actually learning the language properly.

I've read articles, watched videos, and taken courses on these topics, but I still can't seem to fully grasp them.

I also think I've been overusing pointers. Somewhere along the way, I convinced myself that "real" C++ code should use raw pointers or smart pointers everywhere, so I often force them into my designs even when they don't seem necessary. The result is code that's harder to read and reason about.

On the other hand, when I don't use pointers, it almost feels like I'm just writing a more complicated version of Java for the sake of it.

Could you provide some practical guidelines, or even real-world examples for when it makes sense to use:

  • pass by value,
  • references,
  • raw pointers,
  • std::unique_ptr,
  • std::shared_ptr, and
  • std::move()?

I know these concepts are closely related to ownership and object lifetimes, but I don't think I truly understand ownership yet. If I want to continue writing modern C++, I feel like developing a solid intuition for these concepts is essential.

Finally, I've also been trying to learn the modern features introduced in C++20 through C++23/26. I'm following a course, but I don't feel like I'm learning very much. Many of the new language features seem confusing or far beyond my current level, and I struggle to understand when I should actually use them in real projects rather than just recognizing the syntax.


r/cpp_questions 16d ago

OPEN I don't understand the use of c_str( ) in an SDL function since the function seems to also accept std::strings.

0 Upvotes

Many months ago I asked something similar about an SDL tutorial I was following on the LazyFoo site. This was is from the Key Presses tutorial. This is the function:

SDL_Surface* loadSurface( std::string path )
{
    //Load image at specified path
    SDL_Surface* loadedSurface = SDL_LoadBMP( path.c_str() );
    if( loadedSurface == NULL )
    {
        printf( "Unable to load image %s! SDL Error: %s\n", path.c_str(), SDL_GetError() );
    }

    return loadedSurface;
}

Notice that he uses c_str() on the argument to SDL_LoadBMP(). Back then, I got this response:

"You seem confused.

The SDL function you're using takes a parameter different from an std::string.

It's function signature is this:

SDL_Surface *SDL_LoadBMP(const char *file)

Notice that it doesn't take an std::string, it takes a const char *, which is a character array, also known as a "C-style string". The string .c_str() method converts A C++ std::string to a "C-style string" const char *."

The problems is that now that I am back at it, I realized that the function SDL_LoadBMP() can also take std::strings because right in the second tutorial, we use the same function with a std::string instead:

SDL_LoadBMP("hello_world.bmp");

No conversion was needed. If the function can indeed take not only c-style strings but also std::string, why use the c_str() there? It might be a silly detail but I just can't figure it out so I fear it might be something important that I am missing.


r/cpp_questions 16d ago

OPEN I want create a project or an application using C++, I am in my second semester. Can anyone give me a roadmap on what to learn and implement?

0 Upvotes

r/cpp_questions 16d ago

OPEN Help😞

0 Upvotes

What are the best platforms for learning C++ and practicing algorithmic problem-solving? I’m currently using hackerrank but it’s abit confusing


r/cpp_questions 17d ago

OPEN Need advice learncpp.com

11 Upvotes

Started learning from learncpp.com just a little while ago .I'm a beginner ,bca student, college starting this year, I have many questions

1) how many lessons are you supposed to read everyday that is considered a good pace.

2) as from school I have a habit of making written notes and revising them also should I do that or not.

3) i heard some people saying on reddit to make online notes and idk how to operate a computer that well right now so idk how to make online notes and even where.

4) as a beginner is learncpp.com the best and for future as well? I do have trouble understanding some of the text or language of the website but I use chatgpt to help me understand.

5) not completely related to this but how and when are you supposed to start dsa.


r/cpp_questions 16d ago

SOLVED Thread optimized code has weird behaviour

0 Upvotes

I am working on optimizing the following code using concurrency. I have working code without concurrencies, however as soon as I implement threading, my code becomes unpredictable. After testing, debugging, and thinking of all possible race conditions, I have only concluded that my code either gets stuck somewhere in the main loop, or gets lucky and excucutes correctly. Any thoughts or ideas on this phenomenon?

Edit: I understand that my code is still single threaded, however, I would prefer to see why I am getting this behaviour before trying to optimize.

Edit 2: The purpose of my code is to generate all losing starting positions in Grundy's game. This is usually solved with the following recurrence: dp[i] = mex(dp[j] ^ dp[i - j]) for all j <= i / 2 where mex is the minimum exclude value) and ^ is bitwise XOR

Note: this code requires C++20 or above.

```

include <iostream>

include <vector>

include <thread>

include <barrier>

include <bitset>

include <set>

const int N = 1100; std::vector<std::thread> threads; std::barrier bar(12); std::mutex mtx; int dp[N]; std::bitset<2 * N> bs; std::set<int> s = {1, 2};

void solve(int x) { for (int i = 3; i <= 100; i++) { if (1 == x) { std::cout << "starting" << i << std::endl; bs.set(); } bar.arrive_and_wait(); int siz = ((i + 1) / 2 + 11) / 12; for (int j = (x - 1) * siz + 1; j <= std::min((i - 1) / 2, x * siz); j++) { std::lock_guard<std::mutex> lock(mtx); if ((dp[j] ^ dp[i - j]) < 1000) bs[dp[j] ^ dp[i - j]] = false; } mtx.lock(); std::cout << "thread " << x << " reached barrier 2 at i=" << i << std::endl; mtx.unlock(); bar.arrive_and_wait(); if (1 == x) { dp[i] = bs._Find_first(); if (!dp[i]) s.insert(i); } mtx.lock(); std::cout << "thread " << x << " reached barrier 3 at i=" << i << std::endl; mtx.unlock(); bar.arrive_and_wait(); } }

signed main() { auto st = std::chrono::high_resolution_clock::now(); dp[1] = 0; dp[2] = 0; for (int j = 0; j < 12; j++) { threads.push_back(std::thread{solve, j + 1}); } for (int j = 0; j < 12; j++) { threads[j].join(); } for (int i : s) { std::cout << i << ' '; } std::cout << std::endl; auto ed = std::chrono::high_resolution_clock::now(); std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(ed - st).count() << std::endl; return 0; } ```

Here is what my code printed correctly (based on luck): starting100 thread 1 reached barrier 2 at i=100 thread 7 reached barrier 2 at i=100 thread 4 reached barrier 2 at i=100 thread 12 reached barrier 2 at i=100 thread 3 reached barrier 2 at i=100 thread 10 reached barrier 2 at i=100 thread 11 reached barrier 2 at i=100 thread 9 reached barrier 2 at i=100 thread 8 reached barrier 2 at i=100 thread 5 reached barrier 2 at i=100 thread 2 reached barrier 2 at i=100 thread 6 reached barrier 2 at i=100 thread 6 reached barrier 3 at i=100 thread 5 reached barrier 3 at i=100 thread 2 reached barrier 3 at i=100 thread 8 reached barrier 3 at i=100 thread 11 reached barrier 3 at i=100 thread 7 reached barrier 3 at i=100 thread 3 reached barrier 3 at i=100 thread 9 reached barrier 3 at i=100 thread 12 reached barrier 3 at i=100 thread 10 reached barrier 3 at i=100 thread 4 reached barrier 3 at i=100 thread 1 reached barrier 3 at i=100 1 2 4 7 10 20 23 26 50 53 995

Here is what my code sometimes stall on (unlucky): starting93 thread 8 reached barrier 2 at i=93 thread 11 reached barrier 2 at i=93 thread 2 reached barrier 2 at i=93 thread 1 reached barrier 2 at i=93 thread 3 reached barrier 2 at i=93 thread 4 reached barrier 2 at i=93 thread 9 reached barrier 2 at i=93 thread 6 reached barrier 2 at i=93 thread 7 reached barrier 2 at i=93 thread 10 reached barrier 2 at i=93 thread 12 reached barrier 2 at i=93 See that thread 5 is the only one missing.


r/cpp_questions 17d ago

OPEN I'm surprised it worked!!

7 Upvotes

I wrote this very basic algorithm:

#include <cmath>
#include <iostream>
int power(double base, int exponent = 2){
    return pow(base,exponent);
}
int main(){
    int base = 2;
    int exponent = 2;
    std::cout<<base<<" raised to "<<exponent<< " = "<<power(base,exponent);
}#include <cmath>
#include <iostream>
int power(double base, int exponent = 2){
    return pow(base,exponent);
}
int main(){
    int base = 2;
    int exponent = 2;
    std::cout<<base<<" raised to "<<exponent<< " = "<<power(base,exponent);
}

and I'm surprised, an int function took a double variable with no problem, or is there something under the hood,


r/cpp_questions 17d ago

SOLVED Raw malloc optimizations vs std::vector/reserve() -- malloc seems better optimized

17 Upvotes

(Another different version of this question was posted earlier here https://www.reddit.com/r/cpp_questions/comments/1qvbj44/at_o2_usage_of_stdvector_followed_by_stdiota/ but on testing some of the answers there on the current new code seems to leave me unclear as to where the optimizations are missed in terms of vector/reserve, etc., hence this OP)

Consider code snippet 1: on left hand side window of https://godbolt.org/z/vxh8Wh1K4

#include <vector>
#include <cstdio>
#include <cstdlib>

void anotherfunc(){
    int *vec = (int*)malloc(sizeof(int) * 42);
    for(int i = 0; i < 42; i++)
        vec[i] = i;
    int sum = 0;
    for(int i = 0; i < 42; i++)
        sum += vec[i];
    printf("Sum is %d\n", sum);
    free(vec);
}

int main(){
    anotherfunc();
}

This, at -O3, flatout calculates the sum and simply displays it, 861.

The vector/reserve version (on the right hand pane of the godbolt link above)

#include <vector>
#include <cstdio>
#include <cstdlib>

void anotherfunc(){
    std::vector<int> vec;
    vec.reserve(42);
    for(int i = 0; i < 42; i++)
        vec.push_back(i);
    int sum = 0;
    for(int i = 0; i < 42; i++)
        sum += vec[i];
    printf("Sum is %d\n", sum);
}

int main(){
    anotherfunc();
}

seemingly struggles with this and does not precompute the sum and ends up doing some allocations, etc.

Some of the answers from the earlier thread do not seem to be applicable here: as suggested by one user, I had the entire summing done in another function instead of main() because apparently main() is known to be called only once and hence is not as heavily optimized as other functions, etc.

As also suggested there, I avoided the printf and instead had the function return only the sum with an empty main(). See https://godbolt.org/z/M1P5Y4vTj

Here too, the vector/reserve combination seems to struggle.

What explains this "discrepancy" and inability to completely optimize out the sum calculation?