Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get rid of C4800 warning produced by boost::flyweight in VS2008
    text
    copied!<p>I get a warning when compiling below code in VS2008 with MFC turned on. Boost version 1.39</p> <pre><code> 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&lt;key_value&lt;CString, Foo, Conversion&gt;, tag&lt;Foo&gt; &gt; flyweight_test; </code></pre> <p>The last line in the above code produces a warning</p> <p>d:\work\sourcecode\boost1390\boost\functional\hash\extensions.hpp(72) : warning C4800: <code>'const wchar_t *'</code> : forcing value to bool 'true' or 'false' (performance warning)<br> d:\work\sourcecode\boost1390\boost\functional\hash\extensions.hpp(71) : while compiling class template member function <code>size_t boost::hash&lt;T&gt;::operator ()(const T &amp;) const</code> with<br> [<br> <code>T=ATL::CStringT&lt;wchar_t,StrTraitMFC_DLL&lt;wchar_t&gt;&gt;</code><br> ]<br> d:\work\sourcecode\boost1390\boost\multi_index\hashedindex.hpp(1159) : see reference to class template instantiation 'boost::hash&lt;T&gt;' being compiled with<br> [<br> <code>T=ATL::CStringT&lt;wchar_t,StrTraitMFC_DLL&lt;wchar_t&gt;&gt;</code><br> ] </p> <p>This warning goes on and on, through hashed factory, MPL, etc.</p> <p>Why is the warning there and how do I correct the code so no warning is produced? </p> <p>Edit:<br> To fix, add below implementation of hash_value </p> <pre><code> template&lt;typename CharType, typename TraitsType&gt; std::size_t hash_value(const ATL::CStringT&lt;CharType, TraitsType&gt;& s) { return CStringElementTraits&lt;typename TraitsType&gt;::Hash(s); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload