2014-11-07 2 views
1

나는 인터넷에서 다운로드 한이 프로그램을 가지고있다. 마지막에 명확한 부분을 추가하면 다음 메시지와 함께 충돌합니다.부스트를 배우려는 시도 :: 침입자 Q1

[email protected] ~/Documents/BOOST_INTRUSIVE/Intrusive1/bin/Debug $ ./Intrusive1 
Intrusive1: /usr/local/include/boost/intrusive/detail/utilities.hpp:366: void boost::intrusive::detail::destructor_impl(Hook&, boost::intrusive::detail::link_dispatch<(boost::intrusive::link_mode_type)1u>) [with Hook = boost::intrusive::generic_hook<boost::intrusive::get_list_node_algo<void*>, boost::intrusive::member_tag, (boost::intrusive::link_mode_type)1u, (boost::intrusive::base_hook_type)0u>]: Assertion `!hook.is_linked()' failed. 
Aborted 
[email protected] ~/Documents/BOOST_INTRUSIVE/Intrusive1/bin/Debug $ 

확실하지 않은 내용입니다. 모든 항목을 지우고 내용이 삭제되기를 바라고 있습니다.

#include <vector> 
#include <iostream> 

#include <boost/intrusive/list.hpp> 

using namespace boost::intrusive; 

class MyClass : public list_base_hook<> //This is a derivation hook 
{ 
    int anInt; 

public: 
    //This is a member hook 
    list_member_hook<> member_hook_; 

    MyClass(int i) 
     : anInt(i) 
    {} 
}; 

//Define a list that will store MyClass using the public base hook 
typedef list<MyClass> BaseList; 

//Define a list that will store MyClass using the public member hook 
typedef list< MyClass 
      , member_hook< MyClass, list_member_hook<>, &MyClass::member_hook_> 
      > MemberList; 

int main() 
{ 
    typedef std::vector<MyClass>::iterator VectIt; 

    //Create several MyClass objects, each one with a different value 
    std::vector<MyClass> values; 
    for(int i = 0; i < 100; ++i) 
     values.push_back(MyClass(i)); 

    BaseList baselist; 
    MemberList memberlist; 

    //Now insert them in the reverse order in the base hook list 
    for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it) 
     baselist.push_front(*it); 

    //Now insert them in the same order as in vector in the member hook list 
    for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it) 
     memberlist.push_back(*it); 

    //Now test lists 
    { 
     BaseList::reverse_iterator rbit(baselist.rbegin()); 
     MemberList::iterator mit(memberlist.begin()); 
     VectIt it(values.begin()), itend(values.end()); 

     //Test the objects inserted in the base hook list 
     for(; it != itend; ++it, ++rbit) 
      if(&*rbit != &*it) return 1; 

     //Test the objects inserted in the member hook list 
     for(it = values.begin(); it != itend; ++it, ++mit) 
      if(&*mit != &*it) return 1; 

     values.clear(); 
     //Now delete all the values. Do they dissapear from all containers? 
      //Now insert them in the reverse order in the base hook list 
     //for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it) 
     // ; 

     //std::cout << values.size(); 
     //std::cout << baselist.size(); 
     //std::cout << memberlist.size(); 
    } 

    return 0; 
} 

답변

1

관입 용기는하지 자신의 자신의 요소를 않습니다. 요소는 대역 외로 저장되어야합니다. 그들은 여전히 ​​논리적으로 (즉, 그들은 자신의 관입 후크를 통해을 연결되어 있습니다) (수) 침입 컬렉션에 삽입하는 동안 당신이 무슨 일을하는지

는 요소를 삭제합니다.

safe mode에서 Boost Intrusive는 실제로 후크 구조체의 소멸자에서이를 진단하므로 오류 메시지가 나타납니다.

도 참조하십시오. auto-unlink hooks

+0

참조하십시오. 하나의 질문입니다, 나는 그것을 포함하는 모든 관입 컨테이너에서 요소를 제거하고 싶습니다. 엘리먼트에 delete를 호출하면 트릭을 수행 할 것인가? – Ivan

+0

@ 아이반 나는 이것이 실험의 대상이라고 생각 했습니까? ([여기] (http://coliru.stacked-crooked.com/a/c82295df07315cae)). 저장 전에 목록을 지우는 것이 좋습니다. – sehe

+0

그리고 ** ** [자동 연결 해제 버전] (http://coliru.stacked-crooked.com/a/62c48efddbe22985) **이 있습니다. 'values'를 지우면 목록이 지워지는 점에 유의하십시오. 또한 자동 연결 해제 컨테이너로주의 사항 (예 : 스레딩)을 읽으십시오. – sehe

관련 문제