326
-1
submitted 3 years ago* (last edited 3 years ago) by AlmightySnoo@lemmy.world to c/cpp@programming.dev

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.

327
0
328
0
submitted 3 years ago* (last edited 3 years ago) by kalankaboom@hachyderm.io to c/cpp@programming.dev

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

329
0
330
1
331
0
332
0
333
0
C++ Papercuts (www.thecodedmessage.com)
334
0
335
0
336
1
C++ Core Guidelines (isocpp.github.io)
337
0
submitted 3 years ago* (last edited 3 years ago) by AlmightySnoo@lemmy.world to c/cpp@programming.dev

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)

EDIT: Lemmy's sanitization is really bad...

338
0
339
0
Memory Order in C++ (www.sobyte.net)
340
0
341
0
342
0
343
0
344
0

A 3 hours talk by the great Timur!

Part 2 is here: https://inv.zzls.xyz/watch?v=5uIsadq-nyk

345
0
346
0

I'm learning C++ and as starting project I'd like to build a simple TUI program, something like neofetch. Do you have any suggestions of a good library I can use to manage the TUI? After some research I sumbled upon ncurses, which seems quite old tho, and notcurses, which to me looks quite cool. Which of the two would you recommend? Are there any better libraries? I thought that maybe, being quite widely used, ncurses is more worth learning, but I'm open to different opinions.

347
0

This one was quite a struggle, thought I'd share for the C++ programmers here.

I have a use case where for many function templates I have to instantiate them for a bunch of different parameter types, e.g. unary, binary and ternary functions where each argument can be one of 9 different types, giving 9, 9^2 = 81 or 9^3 = 729 instantiations of each function. Clearly I don't want to write those out as explicit template instantiations, and using macros is error prone too.

I've found this approach with std::variant and std::visit to be useful. Would appreciate any insight on edge cases where this may not work, or other suggested approaches.

348
0
349
0
350
-1
view more: ‹ prev next ›

C++

2365 readers
1 users here now

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

Rules

founded 3 years ago
MODERATORS