Search

shared_ptr in unordered_set by Kaba_

Closed
as Fixed Help for as Fixed

2
0
Sign in
to vote
Type: Bug
ID: 734888
Opened: 3/31/2012 11:36:17 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
1
Workaround(s)
2
User(s) can reproduce this bug
The shared_ptr in an unordered_set won't compile. This has something to do with hashing.
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling version

Visual Studio 2010 SP1

Steps to reproduce

#include <unordered_set>
#include <memory>

int main()
{
    std::unordered_set<std::shared_ptr<int> > s;
    return s.count(std::shared_ptr<int>());
}

Product Language

English

Operating System

Windows XP

Operating System Language

English

Actual results

Something about the std::hash not being able to convert shared_ptr to an integer.

Expected results

Compiles.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Andrew Durward on 9/18/2012 at 12:05 PM
Has this been fixed in the version on which it was reported (i.e. MSVC 2010 SP1)? Or only in MSVC 2012?

If the former, could you provide details about how to obtain the patch? My copy of MSVC 2010 SP1 still does not provide a specialization of std::hash for std::shared_ptr as required by the C++11 standard (sec. 20.7.2.6).

Thanks,
andrew
Posted by Microsoft on 4/2/2012 at 10:10 AM
Thank you for reporting this issue to Microsoft. We're glad to say that it has already been fixed.

Tanveer Gani
Visual C++ Team.
Posted by MS-Moderator08 [Feedback Moderator] on 4/1/2012 at 10:29 PM
Thank you for submitting feedback on Visual Studio 11 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.

Posted by MS-Moderator01 on 3/31/2012 at 11:48 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Viorel_ on 3/31/2012 at 12:47 PM
Try defining a hashing function for ‘shared_ptr’. For example:


using namespace std;

template< typename T >
class hash< shared_ptr< T > > : public unary_function< shared_ptr< T >, size_t >
{
    hash< void * > vh;

public:
    size_t operator () (const shared_ptr< int > & z) const
    {
        return vh(z.get());
    }
};