2016-10-11 2 views
1

r 트리에서 값을 제거하려고 할 때 컴파일 오류가 발생합니다. 나는 또한 문제를 일으키는 것으로 보이는 상자와 함께 미가공 포인터를 저장한다. int 나 string 또는 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를 올린다 (boost 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의 네 번째 템플릿 인수를) 재정의를

예제 코드 :

#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 6.2.1 작업, (또한 GCC 4.9.3과 1.58.0 향상) 1.61.0을 높일 나는 나보다 더 나은 솔루션을 좋아

this ticket

+0

에서 영감을, 그것이 많은 청소기 다시 데이터에 액세스 할 수 있습니다. –