MFC をオンにして VS2008 で以下のコードをコンパイルすると、警告が表示されます。ブーストバージョン 1.39
include "boost/flyweight.hpp"
include "boost/flyweight/key_value.hpp"
class Foo
{
public:
Foo(const CString& item) : mfoo(item) {}
const CString& getkeyvalue() const {return mfoo;}
private:
const CString mfoo;
};
struct Conversion
{
const CString& operator() (const Foo& item) const {return item.getkeyvalue();}
};
using namespace boost::flyweights;
flyweight<key_value<CString, Foo, Conversion>, tag<Foo> > flyweight_test;
上記のコードの最後の行で警告が生成されます
d:\work\sourcecode\boost1390\boost\functional\hash\extensions.hpp(72): 警告 C4800::'const wchar_t *'
値を bool 'true' または 'false' に強制しています (パフォーマンス警告)
d:\work\sourcecode\boost1390\ boost\functional\hash\extensions.hpp(71) :
[
] d:\work\sourcecode\boost1390\boost\multi_index\hashedindex.hpp(1159) を使用してクラス テンプレート メンバー関数size_t boost::hash<T>::operator ()(const T &) const
をコンパイル中
: クラス テンプレートのインスタンス化への参照を参照 'boost ::hash<T>' が
[
] でコンパイルされている
T=ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t>>
T=ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t>>
この警告は、ハッシュされたファクトリ、MPL などを介して延々と続きます。
警告が表示される理由と、警告が生成されないようにコードを修正するにはどうすればよいですか?
編集:
修正するには、 hash_value の実装の下に追加します
template<typename CharType, typename TraitsType>
std::size_t hash_value(const ATL::CStringT<CharType, TraitsType>& s)
{
return CStringElementTraits<typename TraitsType>::Hash(s);
}