Binary Integer Literals In C++ 11

Two weeks ago I wrote how happy I was finding out the C++ 14  has gotten around to support binary literals.  However,  If you are stuck with a slightly older compiler (like Visual Studio 2013)   binary literal can also  be easily  expressed in C++ 11!

In his excellent post,  Paul Preney  outlines a tiny framework that will allow writing expressions of the type:

int  can_write_file = 00001_binary;

It is done by user defined literals  processed in by variadic template  functions in a pattern similar to the one outlined in C++ Variadic templates from the ground up.

Roll all the way down to the end of the post for the  complete 50 lines  listing  (including a small demo program)

Leave a Reply

Your email address will not be published. Required fields are marked *