Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2006-11-02 17:02:27


Dave,

Here is a small example which produces errors:

#include <iostream>
#include <functional>
#include <boost/ref.hpp>
#include <boost/bind.hpp>
#include <boost/array.hpp>
#include <boost/utility.hpp>
#include <boost/bind/placeholders.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/map.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/transform.hpp>

using namespace std;
using namespace boost;

template<class T>
struct wrap{};

struct dispatcher
{
        template<class Seq>
        void dispatch()
        {
                int i=0;
                mpl::for_each<typename mpl::transform<Seq, wrap<mpl::_1>
>::type>(bind<void>(*this, i, _1));
                cout << "I did: " << i << " iterations\n";
        }

        template<class T>
        void operator()(int& i, wrap<T>)const
        {
                cout <<"pos: " << i << ", type: " << typeid(T).name() <<
'\n';
                ++i;
        }
};

#include <string>

int main(int argc, char* argv[])
{
        dispatcher d;
        d.dispatch<mpl::map<int, long, double> >();
}

Sorry for so many headers, some of them are not required...

Visual C++ 2005 blames:

c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\map\aux_\preprocessed\plain\map10.hpp(88)
: error C2825: 'P2': must be a class or namespace when followed by '::'
        c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\aux_\preprocessed\plain\map.hpp(68) : see
reference to class template instantiation 'boost::mpl::map3<P0,P1,P2>' being
compiled
        with
        [
            P0=int,
            P1=long,
            P2=double
        ]
        c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\aux_\has_tag.hpp(20) : see reference to
class template instantiation 'boost::mpl::map<T0,T1,T2>' being compiled
        with
        [
            T0=int,
            T1=long,
            T2=double
        ]
        c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\sequence_tag.hpp(112) : see reference to
class template instantiation 'boost::mpl::aux::has_tag<T>' being compiled
        with
        [
            T=boost::mpl::map<int,long,double>
        ]
        c:\program files (x86)\boost\boost_1_33_1\boost\mpl\clear.hpp(29) :
see reference to class template instantiation
'boost::mpl::sequence_tag<Sequence>' being compiled
        with
        [
            Sequence=boost::mpl::map<int,long,double>
        ]
        c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\transform.hpp(113) : see reference to
class template instantiation 'boost::mpl::clear<Sequence>' being compiled
        with
        [
            Sequence=boost::mpl::map<int,long,double>
        ]
        c:\program files (x86)\boost\boost_1_33_1\boost\mpl\eval_if.hpp(41)
: see reference to class template instantiation
'boost::mpl::transform1<P1,P2,P3>' being compiled
        with
        [
            P1=boost::mpl::map<int,long,double>,
            P2=wrap<boost::mpl::_1>,
            P3=boost::mpl::na
        ]
        c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\transform.hpp(138) : see reference to
class template instantiation 'boost::mpl::eval_if<C,F1,F2>' being compiled
        with
        [
 
C=boost::mpl::or_<boost::mpl::is_na<boost::mpl::na>,boost::mpl::is_lambda_ex
pression<wrap<boost::mpl::_1>>,boost::mpl::not_<boost::mpl::is_sequence<wrap
<boost::mpl::_1>>>>,
 
F1=boost::mpl::transform1<boost::mpl::map<int,long,double>,wrap<boost::mpl::
_1>,boost::mpl::na>,
 
F2=boost::mpl::transform2<boost::mpl::map<int,long,double>,wrap<boost::mpl::
_1>,boost::mpl::na,boost::mpl::na>
        ]
        d:\projects\cpp_projects\cpptests\messagewrappertests\main2.cpp(26)
: see reference to class template instantiation
'boost::mpl::transform<Seq1,Seq2OrOperation>' being compiled
        with
        [
            Seq1=boost::mpl::map<int,long,double>,
            Seq2OrOperation=wrap<boost::mpl::_1>
        ]
        d:\projects\cpp_projects\cpptests\messagewrappertests\main2.cpp(81)
: see reference to function template instantiation 'void
dispatcher::dispatch<boost::mpl::map<T0,T1,T2>>(void)' being compiled
        with
        [
            T0=int,
            T1=long,
            T2=double
        ]
c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\map\aux_\preprocessed\plain\map10.hpp(88)
: error C2039: 'first' : is not a member of '`global namespace''
c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\map\aux_\preprocessed\plain\map10.hpp(89)
: error C2146: syntax error : missing ',' before identifier 'first'
c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\map\aux_\preprocessed\plain\map10.hpp(89)
: error C2825: 'P2': must be a class or namespace when followed by '::'
c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\map\aux_\preprocessed\plain\map10.hpp(89)
: error C2039: 'second' : is not a member of '`global namespace''
c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\map\aux_\preprocessed\plain\map10.hpp(90)
: error C2146: syntax error : missing ',' before identifier 'second'
c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\map\aux_\preprocessed\plain\map10.hpp(91)
: error C2977: 'boost::mpl::m_item' : too many template arguments
        c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\map\aux_\item.hpp(79) : see declaration
of 'boost::mpl::m_item'
c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\map\aux_\preprocessed\plain\map10.hpp(92)
: error C2955: 'boost::mpl::m_item' : use of class template requires
template argument list
        c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\map\aux_\item.hpp(79) : see declaration
of 'boost::mpl::m_item'
c:\program files
(x86)\boost\boost_1_33_1\boost\mpl\map\aux_\preprocessed\plain\map10.hpp(92)
: error C2504: 'boost::mpl::m_item' : base class undefined
c:\program files (x86)\boost\boost_1_33_1\boost\mpl\clear.hpp(31) : error
C2504: 'boost::mpl::clear_impl<Tag>::apply<Sequence>' : base class undefined
        with
        [
 
Tag=boost::mpl::aux::sequence_tag_impl<false,false>::result2_<boost::mpl::ma
p<int,long,double>>::type
        ]
        and
        [
            Sequence=boost::mpl::map<int,long,double>
        ]
c:\program files (x86)\boost\boost_1_33_1\boost\mpl\transform.hpp(113) :
error C2039: 'type' : is not a member of 'boost::mpl::clear<Sequence>'
        with
        [
            Sequence=boost::mpl::map<int,long,double>
        ]
c:\program files (x86)\boost\boost_1_33_1\boost\mpl\transform.hpp(113) :
error C3203: 'type' : unspecialized class template can't be used as a
template argument for template parameter 'Sequence', expected a real type
c:\program files (x86)\boost\boost_1_33_1\boost\mpl\transform.hpp(113) :
error C2039: 'type' : is not a member of 'boost::mpl::clear<Sequence>'
        with
        [
            Sequence=boost::mpl::map<int,long,double>
        ]
c:\program files (x86)\boost\boost_1_33_1\boost\mpl\transform.hpp(113) :
error C3203: 'type' : unspecialized class template can't be used as a
template argument for template parameter 'Sequence', expected a real type

Many thanks,

Ovanes

P.S. I am trying to make a map with 150 elements. I posted on this issue 2
posts, can you please take a look?

http://lists.boost.org/boost-users/2006/10/23057.php

-----Original Message-----
From: David Abrahams [mailto:dave_at_[hidden]]
Sent: Thursday, November 02, 2006 10:05 PM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [mpl::map & mpl::transform] Problems
usingmpl::map in mpl::for_each

"Ovanes Markarian" <om_boost_at_[hidden]> writes:

> Hello,
>
> I have some slightly different code, which is presented in C++
> Template Metaprogramming book to use the mpl::for_each function:
>
>
> mpl::for_each< mpl::transform<seq, wrap<_1> >::type
> >(dispatcher_type());

   mpl::for_each<seq, wrap<_> >(dispatcher_type());

would be simpler

> The deviation from the book is that my seq it not mpl::vector<...>,
> but mpl::map<...>
>
> In the docs is written, that mpl::transform operates on Forward
> Sequence. In the doc of forward sequence is stated that mpl::map is a
model of it.

The last release of mpl::map had some considerable bugs. Have you tried the
latest version from the CVS HEAD (or RC_1_34_0)?

> Unfortunately this code does not compile. I could transform the map to
> vector, but I would not like doing it, since that would cost compile
> time and slow down the compilation. Is it a known issue or should not
> I expect map to work with transform?

The code could "not compile" for many other reasons than that "map doesn't
work with transform." Have you tried to compile

        typedef mpl::transform<seq, wrap<_1> >::type x;

> I also tried using itertors on seq, but that did not help.

I think we'll need a lot more detail to be able to help you.

--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

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