How to get rid of the C4800 warning caused by boost :: flyweight in VS2008

I get a warning when compiling below code in VS2008 with MFC enabled. Boost version 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;

The last line in the code above causes a warning

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>>
     ]

, factory, MPL ..

, ?

Edit:
, hash_value


template<typename CharType, typename TraitsType>
std::size_t hash_value(const ATL::CStringT<CharType, TraitsType>& s)
{
    return CStringElementTraits<typename TraitsType>::Hash(s);
}
+3
5

flyweight, , hash_value ( - ) - ATL:: CString. boost, :

std::size_t hash_value(const ATL::CString& s)
{
     // ...
}

, , CString ,

template<typename CharType, typename TraitsType>
std::size_t hash_value(const ATL::CString<CharType, TraitsType>& s)
{
     // calculate hash e.g. by calling hash_value(const std::string&)
}
+2

/Wall, , Boost . , , .

Boost #pragma-, Boost:

// set minimal warning level
#pragma warning(push,0)
// some warnings still occur at this level
// if necessary, disable specific warnings not covered by previous pragma
#pragma warning(disable:4800)

#include 

// restore warning level
#pragma warning(pop)

, , , , , .

, , - Boost , , .

+3

C4800 , int bool.

.

int k = 11;
bool f()
{ return k; }

int k,

k == 0 => *false*
k != 0 => *true*

bool

b == false (internally == 0) => *false*
b == true  (internally == 1) => *true*

( 0) true ++, k bool.

, .

NB: , .

Pseudo C, :

char f()
{
    if( k )
       return (char) 1;
    return (char) 0;
}
+3

, , , cpp:

#pragma warning(disable:4800)

MSDN .

0
source

The warning source is not included in your code. You will have to fix the irreparable Boost code.

0
source

Source: https://habr.com/ru/post/1719605/


All Articles