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

1 に答える 1

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また、参照メンバーを持つことはできません。したがって、このクラス テンプレート全体は、このユース ケースでは壊れています。

于 2016-08-11T15:29:50.060 に答える