4

イテレータ型で -> を使用しようとするとエラーが発生します。イテレータを定義するライブラリを掘り下げると、すべて問題なく、エラーの理由がないように思えます。これがboost::multi_arrayの一部であるコードです:

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

でインスタンス化されconst std::pair<double, unsigned int>&ます。次に、コンパイラは「参照型 'const std::pair<double, unsigned int>&' へのポインタを形成しています」について不平を言います。これらは内部のライブラリの実証です。記録のために、これが私のコードにあるものです:

typedef uint32_t object_indentifier_t;
typedef std::pair< double, object_identifier_t > object_tab_t;
typedef boost::multi_array< object_tab_t, 2 > index_t;

問題を引き起こす使用法は次のとおりです。

object_identifier const& center; // Actually a parameter
index_t::const_subarray<1>::type::const_iterator pos_iterator_left = std::lower_bound( ix[i].begin(), ix[i].end(), sk[i], comparer ); 
assert( pos_iterator_left -> second == center ); // <-- Error steams from here

エラーコンテキストは次のとおりです。

/opt/boost_1_48_0/include/boost/multi_array/iterator.hpp: In instantiation of 'struct boost::detail::multi_array::operator_arrow_proxy<const std::pair<double, unsigned int>&>':
csrc/lsh_cpp/lsh.cpp|125 col 13| required from here
/opt/boost_1_48_0/include/boost/multi_array/iterator.hpp|40 col 10| error: forming pointer to reference type 'const std::pair<double, unsigned int>&'
/opt/boost_1_48_0/include/boost/multi_array/iterator.hpp|43 col 7| error: forming pointer to reference type 'const std::pair<double, unsigned int>&'
 csrc/lsh_cpp/lsh.cpp: In member function 'lsh_cpp::neighbour_iterator_t lsh_cpp::lsh_t::pimpl_t::query(const object_identifier_t&) const':
csrc/lsh_cpp/lsh.cpp|125 col 13| error: result of 'operator->()' yields non-pointer result

注: このクラスは boost::multi_array の一部であり (既に書いています)、直接インスタンス化するつもりはありません。インスタンス化の上に書きました。このクラスは、boost::multi_array によって次のようにインスタンス化されます。

 operator_arrow_proxy<reference>
 operator->() const
 {
     return operator_arrow_proxy<reference>(this->dereference());
 }

「参照」の使用は、参照が意図されていると思わせます。動作しない参照へのアドレスを取る理由はありますか? 自分で数回実行したことを覚えていると思います。元のエイリアス変数のアドレスをそのように取得しました....

4

1 に答える 1

4

参照のアドレスを取得することは問題ではありませんが、参照へのポインターではなく、基になる型へのポインターを返します。参照へのポインターを作成することはできず、参照を再バインドできないため意味がありません。参照型へのポインターを宣言するとエラーになります。

したがって、参照型の場合、戻り値の型T *は機能しません。同様に、 が参照型である場合、参照を再バインドできないため、Ta を宣言しmutable Tても意味がありません。Tしたがって、operator_arrow_proxy非参照を期待するように書かれているようです。

ブーストが常にreference参照型である何かのメンバーでインスタンス化すると、バグのように見えます。実際、バグ #6554として報告されているようです。

于 2013-10-16T08:05:49.623 に答える