在打开 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) :size_t boost::hash<T>::operator ()(const T &) const
使用
[
T=ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t>>
]
d:\work\sourcecode\boost1390\boost\multi_index\hashedindex.hpp(1159) 编译类模板成员函数时:参见类模板实例化的参考 'boost ::hash<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);
}