2016-10-11 5 views
1

rツリーから値を削除しようとするとコンパイルエラーが発生します。私はまた、問題を引き起こしていると思われるボックスと一緒に未処理のポインタを格納する - 私はint、文字列またはshared_ptrを格納する場合、私はエラーを取得しません。ブーストRツリーに生ポインタを格納する際の問題

shared_ptrに切り替えるオプションはありません。これはすべて従来のライブラリに由来しているためです。別の回避策がありますか?

次のように私は木が定義されている次のように

namespace bg = boost::geometry; 
namespace bgi = boost::geometry::index; 
namespace bgm = boost::geometry::model; 

typedef boost::geometry::model::point<float, 2, bg::cs::cartesian> point_t; 
typedef boost::geometry::model::box<point_t> box_t; 
typedef std::pair<box_t, Data*> value_t; 

boost::geometry::index::rtree<value_t, boost::geometry::index::quadratic<16>> rtree; 

そして失敗したコードは次のとおりです。次のように

while(!rtree.empty()) { 
    auto it = rtree.begin(); 
    auto value = *it; 
    rtree.remove(value); // <-- this is where the error appears. 
} 

とエラーは次のとおりです。

...../boost/geometry/index/equal_to.hpp:127:60: error: ambiguous class template instantiation for 'struct boost::geometry::index::detail::equals<NdsInstance*, void>' 
     && detail::equals<T2>::apply(l.second, r.second); 
                 ^
...../boost/geometry/index/equal_to.hpp:28:8: error: candidates are: struct boost::geometry::index::detail::equals<Geometry*, Tag> 
struct equals<Geometry *, Tag> 
    ^
...../boost/geometry/index/equal_to.hpp:37:8: error:     struct boost::geometry::index::detail::equals<T, void> 
struct equals<T, void> 
    ^
...../boost/geometry/index/equal_to.hpp:127:60: error: incomplete type 'boost::geometry::index::detail::equals<NdsInstance*, void>' used in nested name specifier 
     && detail::equals<T2>::apply(l.second, r.second); 
                 ^

全コードサンプルはColliruにあります。私はgcc 4.9.3を使用して1.62を上げています(ブースト1.61と同じエラー)。

答えて

1

私は生のポインタのラッパーを作成することになった:

struct wrapData { 
    public: 
    wrapData(Data *data) { _data = data; } 
    operator Data*() const { return _data; } 
    private: 
    Data *_data; 
}; 

typedef std::pair<box_t, wrapData> value_t; 
1

私は同じ問題を持って、私は歩くための別の方法を見つける:

equal_toファンクタ(RTREEの第四テンプレート引数)を再定義

例コード:GCC 6.2.1に取り組ん

#include <boost/geometry.hpp> 

namespace bg = boost::geometry; 
namespace bgi = boost::geometry::index; 
namespace bgm = boost::geometry::model; 

using point = bgm::point<double, 2, bg::cs::spherical_equatorial<bg::degree>>; 
using value_type = std::pair<point, int*>; 

struct my_equal { 
    using result_type = bool; 
    bool operator() (value_type const& v1, value_type const& v2) const { 
     return bg::equals(v1.first, v2.first) && v1.second == v2.second;} 
}; 

using rtree = bgi::rtree<value_type, bgi::quadratic<16>, bgi::indexable<value_type>, my_equal>; 

int main() { 
    int a,b; 
    rtree rtree; 
    rtree.insert(std::make_pair(point(45,45), &a)); 
    rtree.insert(std::make_pair(point(45,45), &b)); 
    rtree.remove(std::make_pair(point(45,45), &b)); 

    return 0; 
} 

、 (また、GCC 4.9.3に及び1.58.0ブースト)1.61.0を後押し私は私より優れたソリューションを好き

this ticket

+0

からインスピレーションを得た、それは多くのクリーナーバックデータにアクセスすることができます。 –