2016-08-11 1 views
2

화살표 연산자가 부스트 멀티 어레이 반복기에서 누락 되었습니까? 이게 효과가 있다고 기대하는 것이 잘못 되었나요?화살표 연산자 및 부스트 멀티 어레이 반복기

#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

어떤 종류의 컴파일 오류가 발생합니까? –

+0

' '->': 참조 포인터가 불법입니다 .' \ boost \ multi_array \ iterator.hpp – cambunctious

답변

2

버그가있는 것 같습니다. array_iterator::operator-> 리턴한다 :

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

: 여기

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_; 
}; 

그러나 T*foo&* 것 당신은 참조에 대한 포인터를 취할 수 없습니다. 또한 mutable 참조 회원을 가질 수 없습니다. 따라서이 전체 클래스 템플릿은이 사용 사례를 위해 깨졌습니다.

+0

. 쉽게 고칠 수 있을까? – cambunctious

+0

@camunctious 나는 예라고 가정합니다. – Barry