Boost logo

Boost Users :

Subject: [Boost-users] Problems using boost::mpl::for_each
From: Allan Nielsen (a_at_[hidden])
Date: 2012-01-13 04:35:32


Hi,

I have a function where I think mpl::for_each might be use full, but I
can not get it to work:

template<typename SYM>
BaseGamePlateHash holdClear(const BaseGamePlateHash& h) {

    struct ClearSymbol {
        ClearSymbol(BaseGamePlateHash& h) : hash(h) { }
        template <typename _SYM>
        void operator()(_SYM) {
            hash.clear<_SYM>();
        }
        BaseGamePlateHash& hash;
    };

    BaseGamePlateHash new_hash = h;
    typedef typename boost::mpl::remove< SymbolCounts, SYM>::type ClearSymbols;
    ClearSymbol clearsymbol(new_hash);

    clearsymbol(SYM()); // this is working
    //boost::mpl::for_each< boost::mpl::vector<SYM> >( clearsymbol );
// not compiling, this is just a simple test
    //boost::mpl::for_each< ClearSymbols >( clearsymbol ); // not
compiling, this is what I want to do...

    return new_hash;
}

I had the impression that the following two statements would do the same:

clearsymbol(SYM()); // this is working

should be equal to:

boost::mpl::for_each< boost::mpl::vector<SYM> >( clearsymbol ); // not compiling

But this does not seems to be the case...

This is the compile error I get when enabling: boost::mpl::for_each<
boost::mpl::vector<SYM> >( clearsymbol );

test7.cxx:303:13: error: 'holdClear(const BaseGamePlateHash
&)::ClearSymbol::operator()(SymbolCntDice)::ClearSymbol::hash' is not
a member of class 'ClearSymbol'
            hash.clear<_SYM>();
            ^
/usr/local/include/boost/mpl/for_each.hpp:75:9: note: in instantiation
of function template specialization 'holdClear(const BaseGamePlateHash
&)::ClearSymbol::operator()<SymbolCntDice>' requested here
        aux::unwrap(f, 0)(boost::get(x));
        ^
/usr/local/include/boost/mpl/for_each.hpp:100:5: note: in
instantiation of function template specialization
'boost::mpl::aux::for_each_impl<false>::execute<boost::mpl::v_iter<boost::mpl::vector<SymbolCntDice,
mpl_::na, mpl_::na, mpl_::na,
      mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na>, 0>,
boost::mpl::v_iter<boost::mpl::vector<SymbolCntDice, mpl_::na,
      mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, 1>,
boost::mpl::identity<mpl_::na>, ClearSymbol>'
      requested here
    aux::for_each_impl< boost::is_same<first,last>::value >
    ^
/usr/local/include/boost/mpl/for_each.hpp:111:5: note: in
instantiation of function template specialization
'boost::mpl::for_each<boost::mpl::vector<SymbolCntDice, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
      mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>,
boost::mpl::identity<mpl_::na>, ClearSymbol>' requested here
    for_each<Sequence, identity<> >(f);
    ^
test7.cxx:313:5: note: in instantiation of function template
specialization 'boost::mpl::for_each<boost::mpl::vector<SymbolCntDice,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na,
      mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na>, ClearSymbol>' requested here
    boost::mpl::for_each< boost::mpl::vector<SYM> >( clearsymbol );
    ^
test7.cxx:437:36: note: in instantiation of function template
specialization 'holdClear<SymbolCntDice>' requested here
            BaseGamePlateHash hh = holdClear<SYM>( h );
                                   ^
test7.cxx:386:13: note: in instantiation of function template
specialization 'BaseGamePreCalc::create_hold_actions<SymbolCntDice>'
requested here
            create_hold_actions<SymbolCntDice>(hash_enum.first);
            ^
1 error generated.

So, what have I done wrong?

Best regards
Allan W. Nielsen


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