I had a moment last week where I was a little down on my C++, you see I'm a very old programmer, by programmer standards, and my experience with C++ stems from a time before templates, this may amaze and delight in equal measure as template use is so ubiquitous today, however I've been using find & replace style boiler-plate code in the form of both macros and code-gen for literally decades.
Templates however have not been my go to option, because of that weight of experience. I actually find picking apart heavy template code quite hard going at times (I think a lot of us do).
But I was down as a valued colleague (Hi D if you read this, you know it's you) described this approach of mine as "willful ignorance". And he was right, I have to put my hands up and admit he's right.
As such I took a look over my old state machine repo on github and realised there was a bunch of boiler plate stuff I was doing with both macros, or not doing at all, which could easily be made to leverage templates.
Watch this space...
A blog about my rantings, including Games, Game Development, Gaming, Consoles, PC Gaming, Role Playing Games, People, Gaming tips & cheats, Game Programming and a plethora of other stuff.
Showing posts with label templates. Show all posts
Showing posts with label templates. Show all posts
Monday, 15 July 2019
Monday, 25 March 2019
C++ Variadic Template Compiler Optimizations
In my prior post we briefly talked about how the compiler unrolls a variadic template and we needed to provide the end-point function to stop that iteration, lets take a closer look at how the compiler does this unrolling.
The impact this has on your debug build is critical, and I demonstrate that you can see the unrolling of numeric functions (such as summation) but then in release the compiler is smart enough to optimize that all away and use a constant. Understanding when this is happening is a crucial lesson, as we then see the action of a repetitive string output.
If you found these two little videos of any use, please life & subscribe on YouTube to let me know!
And as always the comments below are available.
Labels:
C++,
C++17,
Coding,
Compiler,
Development,
example,
optimization,
programming,
templates,
unrolling,
variadic
Subscribe to:
Posts (Atom)