
I encountered the following problem today which I've reduced down to a simple example. Basically what I want to do is recurse through a typelist (mpl::vector) popping an element each time and end recursion by using apply_if with mpl::empty<List> as the condition. I've made a simple Reverse class template to illustrate the problem. (The Reverse class is of course intended to reverse the contents of a typelist....) --------------------- begin code --------------------- #include <boost/mpl/front.hpp> #include <boost/mpl/push_back.hpp> #include <boost/mpl/pop_front.hpp> #include <boost/mpl/apply_if.hpp> #include <boost/mpl/empty.hpp> #include <boost/mpl/size.hpp> #include <boost/mpl/vector.hpp> using namespace boost::mpl; template <typename List> struct Reverse { typedef typename front<List>::type FrontElem; typedef typename pop_front<List>::type Rest; typedef typename apply_if< empty<Rest>, vector<FrontElem>, typename push_back<typename Reverse<Rest>::Type, FrontElem>::type >::type Type; }; typedef vector<int,int,long> List; typedef Reverse<List>::Type RevList; --------------------- end code ----------------------- When attempting to create the RevList type however, gcc spits the following at me: reverse.cpp: In instantiation of `boost::mpl::pop_front<boost::mpl::vector0<boost::mpl::void_> >': reverse.cpp:15: instantiated from `Reverse<boost::mpl::vector0<boost::mpl::void_> >' reverse.cpp:21: instantiated from `Reverse<boost::mpl::vector1<long int> >' reverse.cpp:21: instantiated from `Reverse<boost::mpl::vector2<int, long int> >' reverse.cpp:21: instantiated from `Reverse<List>' reverse.cpp:25: instantiated from here reverse.cpp:15: base class ` boost::mpl::pop_front_traits<boost::mpl::aux::vector_tag<0>
::algorithm<boost::mpl::vector0<boost::mpl::void_> >' has incomplete type reverse.cpp: In instantiation of `Reverse<boost::mpl::vector0<boost::mpl::void_> >': reverse.cpp:21: instantiated from `Reverse<boost::mpl::vector1<long int> >' reverse.cpp:21: instantiated from `Reverse<boost::mpl::vector2<int, long int> >' reverse.cpp:21: instantiated from `Reverse<List>' reverse.cpp:25: instantiated from here reverse.cpp:15: no type named `type' in `struct boost::mpl::pop_front<boost::mpl::vector0<boost::mpl::void_> >' reverse.cpp:21: no type named `type' in `struct boost::mpl::pop_front<boost::mpl::vector0<boost::mpl::void_> >' reverse.cpp: In instantiation of `Reverse<boost::mpl::vector1<long int> ': reverse.cpp:21: instantiated from `Reverse<boost::mpl::vector2<int, long int> >' reverse.cpp:21: instantiated from `Reverse<List>' reverse.cpp:25: instantiated from here reverse.cpp:21: no type named `Type' in `struct Reverse<boost::mpl::vector0<boost::mpl::void_> >' reverse.cpp: In instantiation of `Reverse<boost::mpl::vector2<int, long int> >': reverse.cpp:21: instantiated from `Reverse<List>' reverse.cpp:25: instantiated from here reverse.cpp:21: no type named `Type' in `struct Reverse<boost::mpl::vector1<long int> >' reverse.cpp: In instantiation of `Reverse<List>': reverse.cpp:25: instantiated from here reverse.cpp:21: no type named `Type' in `struct Reverse<boost::mpl::vector2<int, long int> >' reverse.cpp:25: syntax error before `;' token
I cannot see why it reaches the point where it tries to instantiate Reverse with an empty typelist - the apply_if should stop that (at least that's my intention. Am I being a complete ass somewhere in this code snippet? I've become blinded by now, so if anyone can point out what's wrong I would greatly appreciate it. Sincerely, -- Tarjei