C++

1755 readers
1 users here now

The center for all discussion and news regarding C++.

Rules

founded 1 year ago
MODERATORS
176
177
178
 
 

I was trying to creating a red-black tree, and when trying to get data out of it, it always returned the same value, so i decided to try to create a very simple binary search tree, and i got the same result, so i wonder, ¿what i'm doing wrong when trying to create trees in c++? Here is the code: https://pastebin.com/L2yJJ3Nu

179
180
181
182
 
 

I'm wondering if there are any serious benchmarks that were done recently to show whether C++20 concepts lead to considerable speed-ups in compilation times of templates-heavy code compared to pre-C++20 SFINAE. Would be nice if there was a breakdown by compiler vendor to see which compilers profit the most from replacing SFINAE with concepts.

Anecdotes are of course also welcome.

EDIT(more context): I have a large codebase using lots of expression templates that I wrote in C++17 because at the time our linting tools had incomplete C++20 support, and I used lots of SFINAE too. Right now the tools have evolved and I can afford to use C++20 features now, so I need to guesstimate how much I'm going to gain in compilation times before I go through the large codebase and replace the SFINAE with concepts.

183
9
submitted 1 year ago by lysdexic to c/cpp
184
4
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/cpp
 
 

Hey everyone, I just made something cool!
I wrote a fractal viewer in C++, compiled it to #Wasm using #Emscripten, and put it on my website (https://kalankaboom.net/).

I wrote an article on how I made it, and I would love for you to check it out and give me all the feedback you can!

Here's the article :
https://kalankaboom.net/articles/rewrite_it_in_wasm.html

And here's the tool :
https://kalankaboom.net/projects/mandelwasm/

@cpp
#fractal #mandelbrot #julia #webdev #cpp #art #article

185
6
submitted 1 year ago by lysdexic to c/cpp
186
187
188
189
17
C++ Papercuts (www.thecodedmessage.com)
submitted 1 year ago by jumpstart to c/cpp
190
191
192
16
C++ Core Guidelines (isocpp.github.io)
submitted 1 year ago by lysdexic to c/cpp
193
 
 

Assume you have following C++ snippet:

// i, j, n are of type size_t
// we assume that i, j and n are not optimized away
if((n > 0) && (j < n))
{
  size_t a = i * n +j;
  size_t p = a / n;
  size_t q = a % n;
  // now do something with p and q
  // a is never used afterwards
}

clang 16 and gcc 13.2 with -O2 and -O3 will produce assembly code that computes a exactly as written above and then performs an integer division.

Here's the thing though, it's completely pointless. Ideally the compiler should be able to understand that inside that if block, p and q are respectively always going to be equal to i and j without the need to even compute a or do an integer division. So ideally, the compiler should optimize away a and simply put p = i and q = j.

However, the compiler is not optimizing those away. So maybe it is being careful because i * n +j may overflow? In that case, how would one indicate to the compiler that that won't be a problem?

(the above code is obviously not written by hand in practice, I'd get that very often after inlining functions that manipulate matrix indices and it just frustrates me to see the compiler not understanding that lots pf arithmetic can be avoided)

194
195
17
Memory Order in C++ (www.sobyte.net)
submitted 1 year ago by lysdexic to c/cpp
196
197
8
submitted 1 year ago by lysdexic to c/cpp
198
199
200
view more: ‹ prev next ›