Tag Archives: metaprogramming

Short-circuiting in meta-functions

Short-circuiting in logical operations is a very useful and an often used feature: Should cond_a() evaluate to false, cond_b() is guaranteed not to be evaluated. This is useful for two reasons. One is performance: if cond_b() is an expensive operation … Continue reading

Posted in programming | Tagged , , , | 4 Comments

A friendly type predicate

This is a sequel to the previous post on writing a custom type predicate. One of the readers on Reddit made a very insightful observation. The user has implemented a type that she intends to use with our library, call … Continue reading

Posted in programming | Tagged , , , , , | 1 Comment

Your own type predicate

In this post we will see how to define a type trait or a type predicate or a meta-function that would allow us to check at compile time whether a type exposes an interface that we need. That is, we … Continue reading

Posted in programming | Tagged , , , , , , | 19 Comments

Concepts Lite vs enable_if

This post contains quite advanced material. I assume you are already familiar with Concepts Lite. For an overview of what Concepts Lite is, I recommend this proposal. Also, I have found this blog very useful regarding the details of and … Continue reading

Posted in programming | Tagged , , , | 10 Comments

Diagnosable validity

Certain combinations of types and expressions can make a C++ program ill-formed. “Ill-formed” is a term taken from the C++ Standard and it means that a program is not valid, and compiler must (in most of the cases) reject it. … Continue reading

Posted in programming | Tagged , , , , | 8 Comments

A conditional copy constructor

In this post we will try to define a ‘wrapper’ class template that does or does not have a copy constructor depending on whether the wrapped class has it. This will be a good opportunity to explore in depth a … Continue reading

Posted in programming | Tagged , , , , , | 6 Comments

Meta-functions in C++11

Function and class templates in C++03, along with the ability to specialize them (and to partially specialize the latter), enabled the creation of powerful tools. Perhaps the most prominent one is Boost.MPL library. Not everyone needs to know or needs … Continue reading

Posted in programming | Tagged , | 18 Comments