Tuesday, December 15, 2015

All New Way of Making New

Today marked part two of my quest to document all of my prototype code! Don't forget to mark all your functions and data members with proper comments, kids!

Today was also mainly a day off, but I managed a few lessons in, one of which had me really interested!

Step 1: Member functions can have their own templates, including pesky constructor templates - however, when declaring the general function, the compiler will still try to make one in the case of copy constructor/assignment, so make sure to make normal "dummy" versions.

Step 2: When supporting implicit type conversions in templates (operator*, for example), be sure to use non-member functions. In this entire book I'm reading, the author never once recommends friend functions, but they steal the spotlight here.

Step 3: Trait classes help provide info about a class during compilation. Heck, with overloading functions based on it as a type, it can even do if-elses during compilation!

Step 4: Template metaprogramming is a strange beast (using enums to recursively calculate data for loops?!) but if I dare look into it, the possibilities of policy-based programming (combining independent behaviors) for generative applications are interesting, if not compile-time intensive (but hey! The more you put in the compiler, the less you have to worry about it during run-time!)

Step 5: It's possible to use set_new_handler to provide your own error function during errors regarding new - heck, you can even override and put in the old nothrow (return null) example from 1993!

All this is still a barrage of info that I may not be applying to game programming anytime soon, but it all provides me with quite the arsenal to proceed.

No comments:

Post a Comment