Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#5254 closed Bugs (fixed)

hash template specializations require BOOST_HAS_TR1_HASH work-around

Reported by: Jim Bell <jim@…> Owned by: John Maddock
Milestone: Boost 1.47.0 Component: TR1
Version: Boost Development Trunk Severity: Problem
Keywords: TR1 hash mingw-gcc-4.4 msvc-8 Cc: jim@…

Description

The TR1 docs show the templated hash struct being in namespace std::tr1.

But putting a hash template specialization in std::tr1 doesn't work, at least in cases where BOOST_HAS_TR1_HASH isn't defined.

This is broken for both MinGW-gcc-4.4 and MSVC-8 (VS2005).

See the attached files:

  • TR1_hash_break.cpp doesn't compile for either platform.
  • TR1_hash_workaround.cpp compiles for both.

MSVC-8: Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86

Copyright (C) Microsoft Corporation. All rights reserved.

TR1_hash_break.cpp TR1_hash_break.cpp(21) : error C2888: 'boost::hash<my_key>' : symbol cannot be defined within namespace 'tr1'


MinGW gcc-4.4: TR1_hash_break.cpp:17: error: specialization of 'template<class T> struct boost::hash' in different namespace F:\boost\MinGW-32\trunk\boost/boost/tr1/functional.hpp:127: error: from definition of 'template<class T> struct boost::hash' TR1_hash_break.cpp:19: error: definition of 'size_t boost::hash<my_key>::operator()(const my_key&) const' is not in namespace enclosing 'boost::hash<my_key>'

Attachments (2)

TR1_hash_break.cpp (473 bytes ) - added by Jim Bell <jim@…> 12 years ago.
TR1_hash_workaround.cpp (650 bytes ) - added by Jim Bell <jim@…> 12 years ago.

Download all attachments as: .zip

Change History (9)

by Jim Bell <jim@…>, 12 years ago

Attachment: TR1_hash_break.cpp added

by Jim Bell <jim@…>, 12 years ago

Attachment: TR1_hash_workaround.cpp added

comment:1 by Jim Bell <jim@…>, 12 years ago

Er, forgive the old-style casts on lines 20/25. They ought to be "static_cast<std::size_t>(r)". (Didn't inspect that borrowed code closely enough.)

comment:2 by John Maddock, 12 years ago

Resolution: fixed
Status: newclosed

(In [69508]) Fix typo in inverse_gausian.qbk. Fixes #5254.

comment:3 by Jim Bell <jim@…>, 12 years ago

Resolution: fixed
Status: closedreopened

This ticket concerns tr1/functional.hpp, not libs/math/doc/... Perhaps you typo'd the ticket #.

comment:4 by anonymous, 12 years ago

Grrr, serves me right for working on two at once....

comment:5 by anonymous, 12 years ago

Will fix this shortly by making std::tr1::hash a thin wrapper inheriting from boost::hash, but.... your code will still break on MSVC-10 as there std::tr1::hash is actually an alias for std::hash, and there's nothing we can do at our end to fix that, other than to say don't do that'' :-(

comment:6 by John Maddock, 12 years ago

Resolution: fixed
Status: reopenedclosed

(In [69520]) Make std::tr1::hash a thin wrapper around boost::hash so folks can specialise it. Fixes #5254.

comment:7 by Jim Bell <jim@…>, 12 years ago

I'd love to see the docs, at the point of use (i.e., doc/html/boost_tr1/subject_list.html#boost_tr1.subject_list.hash), mention these portability caveats where we know about them. Do I ask too much?

Note: See TracTickets for help on using tickets.