Reputation: 9582
Is the arrow operator missing from boost multiarray iterators? Am I wrong to expect this to work?
#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;
}
Upvotes: 3
Views: 153
Reputation: 303157
Seems like a bug. array_iterator::operator->
returns a:
// reference here is foo&
operator_arrow_proxy<reference> operator->() const;
Where:
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_;
};
But T*
here would be foo&*
and you can't take a pointer to a reference. Moreover you cannot have a mutable
reference member. So this whole class template is just broken for this use case.
Upvotes: 2