--- Geoffrey Romer wrote:
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?
The arguments will be evaluated if they have typename metaf_<...>::type syntax inside them.
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_
::type, typename insert , at ::type > >::type, m_map ::type type; };
Try:
template <typename m_map>
struct toy_metafunction
{
typedef typename eval_if<
has_key