
Daniel James ha escrito:
On Tue, 20 Mar 2007 17:54:53 -0000, JoaquÃn Mª López Muñoz <joaquin@tid.es> wrote:
Maybe it would be better if boost::hash included a size_t version:
inline std::size_t hash_value(std::size_t v) { return v; }
If necessary, in cases where std::size_t == unsigned int, it could probably use is_same<T,U> to make sure both versions didn't exist and cause warnings/errors.
Sorry, I didn't notice this thread before. This has actually been fixed in 1.34, and 1.35 will have proper suport for 'long long' and 'unsigned long long'. If you can't upgrade when 1.34 is released (which should be soon?), I'd suggest that you add this function to the boost namespace, either in or before the boost headers. It's a pretty nasty hack but the warning is valid so it's worth it.
Hello Daniel, I think you are misunderstanding the problem.: the warning is *not* valid because it happens in 32 bit mode, where std::size_t is a typedef for unsigned int (no longs involved). Please try the following in MSVC 7.1/8.0 in 32 bit mode with /Wp64 compiler option on: #include <boost/functional/hash/hash.hpp> #include <cstddef> int main() { std::size_t x=0; boost::hash<std::size_t>()(x); } If I'm not wrong, you'll get the warning even if using Boost 1.34. The problem is that /Wp64 mode is too smart (or too dumb if you want) and sees a potential problem in casting a std::size_t to an unsigned int (which are the same in 32bit mode) because that cast would pose problems in 64 bit mode. IMHO the right course of action is to not provide overloads for size_t, provide thenm for long and long long types, so guaranteeing that size_t will be covered by some overload either in 32 or 64 bit mode, and then disabling the warning with a // boost/hash/hash.hpp #pragma warning(push) #pragma warning(disable:4267) ... #pragma warning(pop) because even if you've got everything covered /Wp64 won't be able to see it. A good thing about the proposed pragma solution is that by using push/pop facilities you eliminate the warnings inside Boost.Hash without imposing a global warning disabling to the user. HTH, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo