2016-08-11 4 views
2

Fehlt der Pfeiloperator in Boost-Multiarray-Iteratoren? Habe ich falsch zu erwarten, dass das funktioniert?Pfeiloperator und Boost-Multiarray-Iterator

#include <vector> 
#include <boost/multi_array.hpp> 

struct foo { 
    int n; 
}; 

int main() 
{ 
    { 
     std::vector<foo> a; 
     auto it = a.begin(); 
     int test = it->n; // this does compile 
    } 

    { 
     boost::multi_array<foo, 1> a; 
     auto it = a.begin(); 
     int test = it->n; // this does not compile 
    } 
    return 0; 
} 
+0

Welche Art von Kompilierungsfehler tritt auf? –

+0

''->': Zeiger auf Referenz ist unzulässig' in boost \ multi_array \ iterator.hpp – cambunctious

Antwort

2

Scheint wie ein Fehler. array_iterator::operator-> kehrt ein:

// reference here is foo& 
operator_arrow_proxy<reference> operator->() const; 

Wo:

template <class T> 
struct operator_arrow_proxy 
{ 
    operator_arrow_proxy(T const& px) : value_(px) {} 
    T* operator->() const { return &value_; } 
    // This function is needed for MWCW and BCC, which won't call operator-> 
    // again automatically per 13.3.1.2 para 8 
    operator T*() const { return &value_; } 
    mutable T value_; 
}; 

Aber T* hier wäre foo&* und Sie einen Zeiger auf eine Referenz nicht nehmen. Außerdem können Sie kein Referenzelement haben. Also ist diese ganze Klassenvorlage für diesen Anwendungsfall einfach gebrochen.

+0

shucks. Könnte das leicht behoben werden? – cambunctious

+0

@cambunctious Ich nehme ja an. – Barry