https://github.com/wcochran/closest-pairs/blob/main/closest-...
However, your code is full of vector accesses without bounds checking: vec[i] instead of vec.at(i).
That's just as "unsafe" as C, so I recommend not bragging about how far you've come.
Your code is full of what is essentially unprotected C-style
*(addr + i) = ...
... = *(addr + i)
You've been writing C++ since the 1980's, but your code is full of raw pointer math, and yet... "No worries about memory safety"?I have a feeling you'll be reaching for Valgrind or address sanitizer someday soon, just like the C programmers.
This safe, "no worries" C++ was segfaulting. You've managed to make it correct today but it's still unsafe.
Someday one of your coworkers is going to break it and this code will be trashing the heap. Mysterious memory corruption failures are your destiny.
That said, Happy Halloween!
> Someday one of your coworkers is going to break it and this code will be trashing the heap. Mysterious memory corruption failures are your destiny.
You could have written something like, "It's possible this code will break in the future and you won't even realize the cause, because it will appear as a mysterious memory corruption failure."
See how I left out a word like "destiny" and took out the whole bit about coworkers? Yeah, much nicer and less personalized.
The point was that being a C++ programmer is like being part of a horror movie.
I say that as a person who uses C++ in my day job. It's a nightmare.
You obviously have interesting things to say and opinion to share with a fair amount of passion, but the tone detracts from the message, which I find a pity.
We're getting so soft and so fragile, how does it end?
“Hard times create strong men, strong men create good times, good times create weak men, and weak men create hard times." (G. Michael Hopf)
but if you need a bit more speed you can still build with
-O2 -D_GLIBCXX_DEBUG=1 -D_GLIBCXX_DEBUG_PEDANTIC=1 # for libstdc++
-O2 -D_LIBCPP_DEBUG=1 # for libc++
/O2 /D_ITERATOR_DEBUG_LEVEL=1 # for msvc
this way you get compiler optimizations but the assertions are still thereI'm not even certain if using stl containers always use the heap.
I'm a bit confused at times, since I avoid using oop and inheritance, I prefer data oriented, I just write functions and avoid side effects as often as possible.