|
Boost Users : |
From: Cromwell Enage (sponage_at_[hidden])
Date: 2005-10-04 15:25:07
--- 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_<typename has_key<m_map, char>::type,
> typename insert<m_map, pair<char,
> typename plus<int_<1>,
> at<m_map, char>
>
> >::type
> >
> >::type,
> m_map
> >::type type;
> };
Try:
template <typename m_map>
struct toy_metafunction
{
typedef typename eval_if<
has_key<m_map,char>
, insert<
m_map
, pair<
char
, plus<
int_<1>
, at<m_map,char>
>
>
>
, m_map
>::type
type;
};
HTH,
Cromwell D. Enage
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net