2012-03-12 10 views
1

私はboost :: ptr_vector :: pop_front()戻り値の型は何ですか?

...戻り値の型 auto_typeがしかし、:: auto_ptrはにはstd後押し:: shared_ptrのをするために割り当てるこの

typedef ptr_container_detail::static_move_ptr<Ty_,Deleter> auto_type;

ように定義され、失敗したauto_type boost::ptr_vector::pop_front()

を使用して少し問題があります

Error 1 error C2440: 'initializing' : cannot convert from 'boost::ptr_container_detail::static_move_ptr<T,Deleter>' to 'std::auto_ptr<_Ty>' 
Error 1 error C2440: 'initializing' : cannot convert from 'boost::ptr_container_detail::static_move_ptr<T,Deleter>' to 'std::tr1::shared_ptr<_Ty>' 
Error 1 error C2440: 'initializing' : cannot convert from 'boost::ptr_container_detail::static_move_ptr<T,Deleter>' to 'std::tr1::weak_ptr<_Ty>' 

実装を見てみると、pop_frontのように見えるので、フロントにスマートポインタを返してその値を返す必要があります。

auto_type pop_front() 
{ 
    BOOST_ASSERT(!this->empty() && 
        "'pop_front()' on empty container"); 
    auto_type ptr(static_cast<value_type>(this->base().front())); 
           // nothrow 
    this->base().pop_front(); // nothrow 
    return ptr_container_detail::move(ptr); 
} 

しかし、どのタイプがauto_typeですか?

答えて

1

auto_typeは、コピーできない形式のstd :: auto_ptrと考えることができます。オブジェクトを解放すると、ポインタがコンテナから削除され、コンテナのサイズが縮小されます。 nullを格納するコンテナの場合、auto_typeはboolに変換可能であることを利用できます。

if(ptr_vector< nullable<T> >::auto_type r = vec.pop_back()) 
{ 
    ... 
}