Find_if Problem...



  • //Map mit vectoren
    std::map<std::string,std::vector<CModul*> > m_lCombModuls;
    
    //Compare Funktion
    bool ifx(const CModul oScr, UINT iID) { oScr.ModID()==iID; }
    //Zweiter versuch
    //bool ifx(const CModul *pScr, UINT iID) { pScr->ModID()==iID; }
    
    //Hier will ich checken, ob Vector eine Modul mit ein best. ID enthält
    std::find_if(m_lCombModuls[strGroup].begin(),m_lCombModuls[strGroup].end(),std::bind2nd(ifx,iID));
    

    Fehler:

    d:\Projekte\Scheduler\SchedulerV3\WorkflowStateEx2\WorkflowState\Modul.h(110): error C2784: 'std::binder2nd<_Fn2> std::bind2nd(const _Fn2 &,const _Ty &)' : could not deduce template argument for 'overloaded function type' from 'overloaded function type'
    

    HILFE..



  • Per Funktionsobjekt vielleicht?

    struct ifx : std::binary_function< CModul*, UINT, bool >
    {
    	result_type operator()( first_argument_type lhs, second_argument_type rhs ) const
    	{
    		return lhs->ModID() == rhs;
    	}
    };
    

  • Mod

    Wie sehen denn die nachfolgenden Erläuterungen des Compilers zu diesem Fehler auf? Falls ifx überladen ist, musst du die resultierende Mehrdeutigkeit manuell (per static_cast in den gewünschten Funktionstyp) auflösen.

    std::find_if(m_lCombModuls[strGroup].begin(),m_lCombModuls[strGroup].end(),std::bind2nd(static_cast<bool(&)(CModul,UINT)>(ifx),iID));
    


  • Wie soll das funktionieren? 😮 Alternativen wären evtl noch boost::bind (die Bibliothek unterstützt auch Funktionen) oder std::ptr_fun;

    bool ifx( CModul* oScr, UINT iID) { return oScr->ModID()==iID; }
    // ...
    std::find_if(m_lCombModuls[strGroup].begin(),m_lCombModuls[strGroup].end(),std::bind2nd(std::ptr_fun( ifx ),iID));
    

  • Mod

    oh stimmt, wir brauchen erst einen Adapter ... hab mich schon zu sehr an boost::bind gewöhnt


Anmelden zum Antworten