Probleme mit Boost MPL (Lambda und Transform)



  • Hallo!

    Ich möchte mich gerne in Boost MPL (Sequence und Lambda) einarbeiten und verstehe die Compilerfehler nun nicht mehr (es wird nur noch in die MPL-Bibliothek verwiesen).

    Hier der Code:

    template<typename Formula>
    struct negate
    {
    	typedef typename Formula::negated type;
    };
    
    // ------------------------------------------------------------------------
    //	Term
    // ------------------------------------------------------------------------
    template<typename Polarity>
    struct term 
    {
    	typedef typename term<Polarity> negated;
    };
    
    // ------------------------------------------------------------------------
    //	Formula
    // ------------------------------------------------------------------------
    template
    	<typename Polarity, typename Junctor, typename Sequence>
    struct connected
    {
    	// Negated Formula
    	typedef typename connected<mpl::not_<Polarity>, Junctor, Sequence> negated;
    
    	typedef typename mpl::lambda< negate <mpl::_1> > neg;
    
    	typedef typename mpl::transform<Sequence, neg >::type neg_sequence;
    };
    
    ...
    
    typedef connected<mpl::true_, and, term<mpl::false_ > > f;
    f::neg_sequence l;
    

    Problematisch ist die letzte Typdefinition. Ich möchte erreichen, dass jedes Element in Sequence negiert wird, also neg aufgerufen wird.

    Vielen Dank für eure Hilfe

    Schöne Grüße
    Tobias Philipp


  • Administrator

    Nur weil du die Fehlermeldung nicht mehr verstehst, heisst das nicht, dass wir damit auch nicht klar kommen. Es ist sehr schwer einfach so auf Anhieb ohne genauere Angaben rauszufinden, was hier falsch ist. Die Fehlermeldungen sind zwar komplex, aber meistens sehr hilfreich.

    Grüssli



  • Danke für deine schnelle Antwort. Bisher kam ich mit den Fehlermeldungen auch klar, aber es wurde auf meinem Quelltext verwiesen. Zur Not konnte ich da noch raten 😉

    Hier noch die Fehlermeldung. Ich dachte nicht, dass diese weiterhilft. Achja, kompiliert wurde mit Visual Studio 2008:

    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\clear.hpp(30) : error C2903: 'apply' : symbol is neither a class template nor a function template
    1>        c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : see reference to class template instantiation 'boost::mpl::clear<Sequence>' being compiled
    1>        with
    1>        [
    1>            Sequence=miniplan::term<boost::mpl::false_>
    1>        ]
    1>        c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\eval_if.hpp(41) : see reference to class template instantiation 'boost::mpl::transform1<P1,P2,P3>' being compiled
    1>        with
    1>        [
    1>            P1=miniplan::term<boost::mpl::false_>,
    1>            P2=miniplan::connected<boost::mpl::true_,miniplan::and,miniplan::term<boost::mpl::false_>>::neg,
    1>            P3=boost::mpl::na
    1>        ]
    1>        c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(138) : see reference to class template instantiation 'boost::mpl::eval_if<C,F1,F2>' being compiled
    1>        with
    1>        [
    1>            C=boost::mpl::or_<boost::mpl::is_na<boost::mpl::na>,boost::mpl::is_lambda_expression<miniplan::connected<boost::mpl::true_,miniplan::and,miniplan::term<boost::mpl::false_>>::neg>,boost::mpl::not_<boost::mpl::is_sequence<miniplan::connected<boost::mpl::true_,miniplan::and,miniplan::term<boost::mpl::false_>>::neg>>>,
    1>            F1=boost::mpl::transform1<miniplan::term<boost::mpl::false_>,miniplan::connected<boost::mpl::true_,miniplan::and,miniplan::term<boost::mpl::false_>>::neg,boost::mpl::na>,
    1>            F2=boost::mpl::transform2<miniplan::term<boost::mpl::false_>,miniplan::connected<boost::mpl::true_,miniplan::and,miniplan::term<boost::mpl::false_>>::neg,boost::mpl::na,boost::mpl::na>
    1>        ]
    1>        c:\users\tobias\desktop\lala\miniplan\liblogic\static_formula.h(105) : see reference to class template instantiation 'boost::mpl::transform<Seq1,Seq2OrOperation>' being compiled
    1>        with
    1>        [
    1>            Seq1=miniplan::term<boost::mpl::false_>,
    1>            Seq2OrOperation=miniplan::connected<boost::mpl::true_,miniplan::and,miniplan::term<boost::mpl::false_>>::neg
    1>        ]
    1>        c:\users\tobias\desktop\lala\miniplan\liblogic\liblogic.cpp(19) : see reference to class template instantiation 'miniplan::connected<Polarity,Junctor,Sequence>' being compiled
    1>        with
    1>        [
    1>            Polarity=boost::mpl::true_,
    1>            Junctor=miniplan::and,
    1>            Sequence=miniplan::term<boost::mpl::false_>
    1>        ]
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\clear.hpp(30) : error C2039: 'apply' : is not a member of 'boost::mpl::clear_impl<boost::mpl::non_sequence_tag>'
    1>        c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\aux_\clear_impl.hpp(31) : see declaration of 'boost::mpl::clear_impl<boost::mpl::non_sequence_tag>'
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\clear.hpp(30) : error C2955: 'boost::mpl::apply' : use of class template requires template argument list
    1>        c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\aux_\preprocessed\plain\apply.hpp(134) : see declaration of 'boost::mpl::apply'
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\clear.hpp(30) : error C2143: syntax error : missing ',' before '<'
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : error C2039: 'type' : is not a member of 'boost::mpl::clear<Sequence>'
    1>        with
    1>        [
    1>            Sequence=miniplan::term<boost::mpl::false_>
    1>        ]
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : error C2146: syntax error : missing ',' before identifier 'type'
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : error C2065: 'type' : undeclared identifier
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : error C3203: 'back_inserter' : unspecialized class template can't be used as a template argument for template parameter 'In', expected a real type
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : error C2955: 'boost::mpl::back_inserter' : use of class template requires template argument list
    1>        c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\back_inserter.hpp(28) : see declaration of 'boost::mpl::back_inserter'
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : error C2039: 'type' : is not a member of 'boost::mpl::clear<Sequence>'
    1>        with
    1>        [
    1>            Sequence=miniplan::term<boost::mpl::false_>
    1>        ]
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : error C2146: syntax error : missing ',' before identifier 'type'
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : error C2065: 'type' : undeclared identifier
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : error C3203: 'front_inserter' : unspecialized class template can't be used as a template argument for template parameter 'In', expected a real type
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : error C2955: 'boost::mpl::front_inserter' : use of class template requires template argument list
    1>        c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\front_inserter.hpp(27) : see declaration of 'boost::mpl::front_inserter'
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : error C3203: 'transform1_impl' : unspecialized class template can't be used as a template argument for template parameter 'T2', expected a real type
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : error C2955: 'boost::mpl::aux::transform1_impl' : use of class template requires template argument list
    1>        c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(40) : see declaration of 'boost::mpl::aux::transform1_impl'
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : error C3203: 'reverse_transform1_impl' : unspecialized class template can't be used as a template argument for template parameter 'T3', expected a real type
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : error C2955: 'boost::mpl::aux::reverse_transform1_impl' : use of class template requires template argument list
    1>        c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(57) : see declaration of 'boost::mpl::aux::reverse_transform1_impl'
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : error C2955: 'boost::mpl::if_' : use of class template requires template argument list
    1>        c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\if.hpp(56) : see declaration of 'boost::mpl::if_'
    1>c:\users\tobias\documents\downloads\boost_1_38_0\boost_1_38_0\boost\mpl\transform.hpp(113) : fatal error C1903: unable to recover from previous error(s); stopping compilation
    1>Build log was saved at "file://c:\Users\Tobias\Desktop\lala\miniplan\liblogic\Debug\BuildLog.htm"
    1>liblogic - 20 error(s), 1 warning(s)
    

  • Administrator

    Hmmm, das Problem scheint recht trivial zu sein. Deine Sequence ist schlicht und einfach gesagt keine Sequence. Sie erfüllt das Konzept der Forward Sequence nicht.

    Transform:
    http://www.boost.org/doc/libs/1_38_0/libs/mpl/doc/refmanual/transform.html

    Erwartet eine Sequence, welche das Konzept Forward Sequence erfüllt:
    http://www.boost.org/doc/libs/1_38_0/libs/mpl/doc/refmanual/forward-sequence.html

    Du übergibst term<mpl::false_ > , was überhaupt nichts mit einer solchen Sequenz zu tun hat. Mach daraus z.B. ein mpl::vector<term<mpl::false_> > und schon kompiliert es.

    Grüssli



  • Ach Mist! Das hatte ich übersehen.

    Vielen Dank, es funktioniert. Schon gut, wenn ein anderer auch mal drauf guckt 🙂


Anmelden zum Antworten