Boost logo

Boost Users :

Subject: [Boost-users] mpl code does not compile with GNU-C++ 4.2.2
From: peter_foelsche_at_[hidden]
Date: 2008-09-30 17:07:20


#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/range_c.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/transform_view.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/mpl/size.hpp>
#include <utility>
#include <boost/noncopyable.hpp>
#include <boost/mpl/zip_view.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/back.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/equal.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/max_element.hpp>
#include <assert.h>

template<typename CDB>
struct CDer
{
        typedef CDer<CDB> CThis;
        typedef boost::mpl::zip_view<boost::mpl::vector<CDB, CDB> > CMerged;

        static const unsigned int XSIZE = boost::mpl::size<CDB>::value;
        template</*typename CDB, */typename CDB1, typename CMultiply>
        struct CCreatePair
        {
                CMultiply &m_rOp;
                CCreatePair(CMultiply& op)
                        : m_rOp(op)
                {
                }
                typedef void result_type;
                template<typename T>
                struct wrap
                {
                };
                template<typename T>
                void operator ()(wrap<T>) const
                {
                        typedef typename boost::mpl::front<T>::type first;
                        typedef typename boost::mpl::back<T>::type second;

                        m_rOp(std::make_pair(first::value, second::value));
                }
        };
        template<typename CDB1>
        struct CCopy:private boost::noncopyable
        { CThis &m_r0;
                const CDer<CDB1> &m_r1;
                unsigned int m_iPos;
                CCopy(const CDer<CDB1> &_r1, CThis &_r0)
                    :m_r0(_r0),
                     m_r1(_r1),
                     m_iPos(0)
                {
                }
                void operator()(const std::pair<bool, bool> &_r)
                {
                }
                
        };
        template<typename CDB1>
        struct CTargetEqualOrGreater
        { typedef CTargetEqualOrGreater<CDB1> type;
                typedef typename boost::mpl::transform<
                        CDB,
                        CDB1,
                        boost::mpl::not_<
                                boost::mpl::or_<
                                        boost::mpl::and_<
                                                boost::mpl::not_<boost::mpl::_1>,
                                                boost::mpl::not_<boost::mpl::_2>
>,
                                        boost::mpl::_1
>
>
>::type CBoolVector;
                typedef typename boost::mpl::max_element<CBoolVector>::type CMaxElement;
                typedef typename boost::mpl::deref<CMaxElement>::type CDeRef;
                static const bool value = CDeRef::value == false;
        };
        CDer(void)
        {
        }
        template<typename CDB1>
        CDer(const CDer<CDB1> &_r)
        {
                CCopy<CDB1> sCopy(_r, *this);
                CCreatePair<CDB1, CCopy<CDB1> > sCreatePair(sCopy);
                boost::mpl::for_each<CMerged, CCreatePair<CDB1, CCopy<CDB1> >::wrap<boost::mpl::_1> >(sCreatePair);
                BOOST_MPL_ASSERT( (CTargetEqualOrGreater<CDB1>));
        }
        template<typename CDB1>
        CThis &operator=(const CDer<CDB1> &_r)
        {
                CCopy<CDB1> sCopy(_r, *this);
                CCreatePair<CDB1, CCopy<CDB1> > sCreatePair(sCopy);
                boost::mpl::for_each<CMerged, CCreatePair<CDB1, CCopy<CDB1> >::wrap<boost::mpl::_1> >(sCreatePair);
                BOOST_MPL_ASSERT( (CTargetEqualOrGreater<CDB1>));
                return *this;
        }
};

int main()
{ typedef CDer<
                boost::mpl::vector<
                        boost::mpl::true_,
                        boost::mpl::true_,
                        boost::mpl::true_,
                        boost::mpl::true_
> > CDerBSIM3;

        const CDerBSIM3 b;
        const CDerBSIM3 a(b);

        return 0;
}

the compiler says:

main.cpp: In constructor 'CDer<CDB>::CDer(const CDer<CDB1>&)':
main.cpp:96: error: parse error in template argument list
main.cpp: In member function 'CDer<CDB>& CDer<CDB>::operator=(const CDer<CDB1>&)':
main.cpp:104: error: parse error in template argument list

This is exactly the for_each line.

Peter


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