Posts (Page 3)

A Nice Way to Manage SDL Resource Lifetime

February 21, 2016

I happen to use the SDL library when i need to display graphics on the screen, but want to do it simpler than with OpenGL. SDL is easy to use and portable, but it is a C-style library. Because of that C nature, the library does not really help the user to write elegant, modern code. Acquiring and Releasing SDL resources often ends up in ugly old school resource management. It is not hard to fix that, and this article shows how useful shared_ptr from the STL is in such cases. The approach is easily extendable to other kinds of resources, too.

Read more

A __FILE__ Macro Which Does Not Contain the Whole Source File Path

February 20, 2016

The __FILE__ macro expands to the current source file name at compile time. It is not really useful if the source file paths which the build system uses, are very long, as this would bloat log output with long path names. It would be useful to have a shortened version, which only contains the file name without the whole path. This article describes how to implement a __SHORT_FILE__ macro, that does not add any run time overhead.

Read more

How Does the Typical SFINAE Type Trait Work?

February 19, 2016

C++ type traits can be implemented using an interesting technique which uses the SFINAE principle. This article explains what SFINAE means, how it works and how it can be used to implement useful type traits.

Read more

What is a Type Trait?

February 18, 2016

This article explains, how so called type traits in C++ work. Type traits have been there for quite a long time now. They are a meta programming technique which appears to use types and their sub types like functions at compile time, to control what the compiler actually compiles.

Read more