I'm struggling with a problem of how to correctly use conditionals in
MPL. In a nutshell, the problem is that the compiler greedily
evaluates all parts of a conditional, even the branch that isn't
followed. This is a problem not just for performance, but because
sometimes the unused branch might not compile.
I know that eval_if is supposed to address this problem, but unless
I'm missing something, it doesn't seem to be a complete solution. It
delays evaluating the branches until one of them is selected, but the
compiler still evaluates the *arguments* to both branches. If the
arguments themselves don't compile, I'm screwed, despite the fact that
the parts of my code that are actually relevant (the branches that get
used) are perfectly correct.
How do I resolve this problem?
Here's a toy example, a metafunction which, given a map, finds the
value associated with the key "char" and, if it exists, increments the
associated value (which we assume is numeric):
template <typename m_map>
class toy_metafunction
{
typedef typename
if_