2012-05-08 6 views
4

これはBoostバグですか、何か間違っていますか?ブースト高速プールアロケータは関数ポインタに問題がありますか?

#include <map> 
#include <boost/pool/pool_alloc.hpp> 

int main() 
{ 
    typedef const std::string key; 
    typedef double* (*value)(const int&); 
    std::map<key, value, std::less<key>> map_with_standard_allocator; // works 
    std::map<key, value, std::less<key>, boost::fast_pool_allocator<std::pair<const key, value> > > map_with_boost_allocator; // fails 
} 

最後の行は、Microsoft Visual Studio 2008でBoost 1.40および1.48でコンパイルできません。しかし、g ++ 4.5.3(Cygwin)ではうまくコンパイルされます。

エラーは、次のとおりです。(私は誤ってこの回答への以前の編集に記載)

1>Compiling... 
1>main.cpp 
1>C:\UniLib1\trunk\External\boost/pool/pool_alloc.hpp(205) : error C2535: 'const std::basic_string<_Elem,_Traits,_Ax> *boost::fast_pool_allocator<T,UserAllocator,Mutex,NextSize>::address(const std::basic_string<_Elem,_Traits,_Ax> &)' : member function already defined or declared 
1>  with 
1>  [ 
1>   _Elem=char, 
1>   _Traits=std::char_traits<char>, 
1>   _Ax=std::allocator<char>, 
1>   T=const std::basic_string<char,std::char_traits<char>,std::allocator<char>>, 
1>   UserAllocator=boost::default_user_allocator_new_delete, 
1>   Mutex=boost::details::pool::default_mutex, 
1>   NextSize=32 
1>  ] 
1>  C:\UniLib1\trunk\External\boost/pool/pool_alloc.hpp(202) : see declaration of 'boost::fast_pool_allocator<T,UserAllocator,Mutex,NextSize>::address' 
1>  with 
1>  [ 
1>   T=const std::basic_string<char,std::char_traits<char>,std::allocator<char>>, 
1>   UserAllocator=boost::default_user_allocator_new_delete, 
1>   Mutex=boost::details::pool::default_mutex, 
1>   NextSize=32 
1>  ] 
1>  c:\Program Files\Microsoft Visual Studio 9.0\VC\include\xtree(137) : see reference to class template instantiation 'boost::fast_pool_allocator<T,UserAllocator,Mutex,NextSize>' being compiled 
1>  with 
1>  [ 
1>   T=const std::basic_string<char,std::char_traits<char>,std::allocator<char>>, 
1>   UserAllocator=boost::default_user_allocator_new_delete, 
1>   Mutex=boost::details::pool::default_mutex, 
1>   NextSize=32 
1>  ] 
1>  c:\Program Files\Microsoft Visual Studio 9.0\VC\include\map(78) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled 
1>  with 
1>  [ 
1>   _Traits=std::_Tmap_traits<key,value ,std::less<key>,boost::fast_pool_allocator<std::pair<key,value >>,false> 
1>  ] 
1>  .\main.cpp(9) : see reference to class template instantiation 'std::map<_Kty,_Ty,_Pr,_Alloc>' being compiled 
1>  with 
1>  [ 
1>   _Kty=key, 
1>   _Ty=value, 
1>   _Pr=std::less<key>, 
1>   _Alloc=boost::fast_pool_allocator<std::pair<key,value >> 
1>  ] 
+1

コンパイラエラーとは何ですか? – user7116

+0

ブースト1.40?すでに1.49になっていますか? – PlasmaHH

+0

'std :: pair 'ではないでしょうか? –

答えて

1

これはVS2008でバグではありません。 C++ 03標準では、std::mapのような連想型コンテナのキータイプは、 'assignable'でなければなりません(23.1.2 "連想型コンテナ"の表69による)。 const std::stringは割り当てできません。 C++ 11標準では、この要件を緩和するようだが、新基準は、それはコンパイラがでstd::mapを使用しようとするコードを診断するために必要であることが私にははっきりしていないVC以来++ 2008

には適用されないことに注意してください割り当て不可能なキーなので、私はGCCやVC++ 2010がこのコードを不適切に受け入れていると主張することはできないと思います(私はそれがあなたが期待するかもしれない未定義コードの領域に入ると思います。仕事をする)。しかし、VC++ 2008がコンパイルを拒否しても問題ないことは明らかです。

私は、アロケータのaddress()関数をマップの要素ではなくマップの要素にパラメータ化するVC++ 2008のライブラリがまだ疑わしいと思っています(興味があればこの回答の最初の編集を参照してください) std::pair<>がマップ要素を保持するために使用されて以来、キー部分が要素全体と同じアドレスになるように常に設定されるので、実際のバグは存在しないと考えてください。

関連する問題