Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3420570
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:01:41+00:00 2026-05-18T06:01:41+00:00

I want to use data structure that serves like .Net HashSet, I tried to

  • 0

I want to use data structure that serves like .Net HashSet, I tried to use unordered_set with the default hashing method and custom comparer as follows:

struct comparer
    {
        bool operator()( const TCHAR* first,const TCHAR* second) const
        {   
            return _tcscmp((TCHAR*)first,(TCHAR*)second) == 0;
        }
    };

    typedef unordered_set<const TCHAR*,hash<const TCHAR*>,comparer> HashSet;

the problem is when I tried to use the HashtSet to find specific key (using find method) that is I just added using insert it returns HashSet::end()!!

Could you explain what is the problem?
I’m using VC++ under VS2010

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T06:01:41+00:00Added an answer on May 18, 2026 at 6:01 am

    Assuming that hash here is std::hash, there is no specialization of std::hash for char* or wchar* other than the generic specialization for any pointer type, that hashes based on the pointer value.

    So, if you want to use TCHAR* as a hash key, with the hash based on the string contents instead of the pointer value, you’ll need to supply a different hash functor class.

    There are specializations of std::hash for string and wstring, that I think you could use if you pick the right one according to _UNICODE. I say “I think” because TCHAR* should just convert to string or wstring, but if I’ve missed something then you could write a simple wrapper.

    If you were going to do either of those, though, then you could just as well use string or wstring as the hash key, since everything will need to be converted for hashing anyway. This will also allow you to add strings to your unordered_set without having to keep them hanging around until they’re removed. With your code above, I imagine it’s a nuisance adding anything other than string literals to the set.

    If you’re worried about speed, and not worried about managing the strings, then pick your favourite string hashing algorithm and apply it to the string data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What method do you use when you want to get performance data about specific
I want to use data binding with an XML document to populate a simple
I want to use Google spreadsheets to store data online so multiple people can
I'm using System.Data.Linq.DataContext file for accessing a mdf Database I want to use the
I want to use Powershell to write some utilities, leveraging our own .NET components
I want to use the MultipleLookupField control in a web page that will run
Below is my stored procedure. I want use stored procedure select all row of
I want to use the mouse scrollwheel in my OpenGL GLUT program to zoom
I want to use the functions exposed under the OpenGL extensions. I'm on Windows,
I want to use the Publish.GacRemove function to remove an assembly from GAC. However,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.