lambda als template parameter



  • hi leute

    folgender code

    class bounding_rect
    {
       public:
    
          auto result(void) const noexcept -> const rect&
          {
             return m_result;
          }
    
          auto reset(void) noexcept -> void
          {
             m_result = rect();
          }
    
          auto operator()(const rect &r) noexcept -> bounding_rect&
          {
             if(r.left < m_result.left)
                m_result.left = r.left;
    
             if(r.top < m_result.top)
                m_result.top = r.top;
    
             if(m_result.right < r.right)
                m_result.right = r.right;
    
             if(m_result.bottom < r.bottom)
                m_result.bottom = r.bottom;
    
             return *this;
          }
    
          auto operator()(const rect r[]) noexcept -> bounding_rect&
          {
             const int count = sizeof(r) / sizeof(rect);
    
             for(int i = 0;i < count; ++i)
                operator()(r[i]);
    
             return *this;
          }
    
          auto operator()(const rect *rc, int count) noexcept -> bounding_rect&
          {
             for(int i = 0;i < count; ++i)
                operator()(rc[i]);
    
             return *this;
          }
    
          template<class T, class EXTRACTOR>
          auto operator()(const T &obj, EXTRACTOR ex) noexcept -> bounding_rect&
          {
             operator()(ex(obj)); // (2)
    
             return *this;
          }
    
          template<class T, class EXTRACTOR>
          auto operator()(const T obj[], EXTRACTOR ex) noexcept -> bounding_rect& // (1)
          {
             const int count = sizeof(obj) / sizeof(T);
    
             for(int i = 0;i < count; ++i)
                operator()(obj[i], ex);
    
             return *this;
          }
    
          template<class T, class EXTRACTOR>
          auto operator()(const T *obj, int count, EXTRACTOR ex) noexcept -> bounding_rect&
          {
             for(int i = 0;i < count; ++i)
                operator()(obj[i], ex);
    
             return *this;
          } 
    
       private:
          rect m_result;
    }; /* class bounding_rect */
    

    das ist eine kleine klasse um von erwiterten RECTs das umschließende rechteck zu finden.
    nun habe ich die rects nicht nur als array sondern auch als member in anderen klassen die wiederum als array vorliegen.
    habe also noch template operator() funktionen gebaut wo ich den extractor der rects mit uebergebe.
    schaut dann z.b. so aus:

    txl::gui::cc::edit edit_rects[edit_rect_ids::items_count];
       edit_rects[0].rect = txl::geom::rect(4);
       edit_rects[1].rect = txl::geom::rect(5);
       edit_rects[2].rect = txl::geom::rect(6);
       edit_rects[3].rect = txl::geom::rect(7);
    
          txl::geom::bounding_rect bounds;
       bounds(edit_rects, [](txl::gui::cc::edit &e) noexcept -> const txl::geom::rect& { return e.rect; } );
    

    in dem beispiel wird dann (1) aufgerufen.
    beim komilieren bekomme ich dann einen fehler in (2):

    1>error C2664: "txl::geom::rect &WinMain::<lambda_c25109f46be8b62295f4e8bdb5288d02>::operator ()(txl::gui::cc::edit &)
     noexcept const" : Konvertierung von Argument 1 von "const txl::gui::cc::edit"
     in "txl::gui::cc::edit &" nicht möglich
    

    kann mir jemand sagen wo ich da den fehler habe ?

    Meep Meep


  • Mod

    Warum kein vollständiges Minimalbeispiel? Du solltest doch eigentlich wissen, dass du es allen Helfern bloß unnötig schwer machst, wenn sie deinen Fehler nicht selber nachvollziehen können.



  • hab den fehler gefunden.
    im parameter der lambda funktion hat const gefehlt.
    10 mal angeschaut und immer uebersehen

    Meep Meep


Anmelden zum Antworten