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 8766761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:37:56+00:00 2026-06-13T16:37:56+00:00

I need to hash a combination of four different things, comprising 20 bytes, as

  • 0

I need to hash a combination of four different things, comprising 20 bytes, as such I defined this:

struct holder
{
  char a;
  uint16_t b;
  uint64_t c;
  char d[9];
} __attribute((__packed__));

and then I can load one of the above and pass it to a hash function. So then I want my class Foo to have a std::tr1::unordered_map<holder, int> map. but in order to declare that in the header file for Foo, I need to include the definition of holder, the template specialization inside std::tr1 for hash for my type, and as a result the full hash function. Is there a way to not have all this code up in the header but still give my class this hashmap?

  • 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-06-13T16:37:58+00:00Added an answer on June 13, 2026 at 4:37 pm

    Simply declare the function in a header file, and define it at a cpp file.

    This would look like:

    // Header
    namespace std { namespace tr1
    
    // Define specialization
    template<>
    struct hash<holder>: unary_function<holder, size_t> {
        // Declare member
        size_t operator()(holder const&) const;
    };
    
    } }
    
    // Source
    
    // Define member
    std::size_t std::tr1::hash<holder>::operator()(holder const&) const
    { /* implementation */ }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to run into this very often. I need to build a Hash
I need this Hash {peter => [apple, orange, mango], sandra => [flowers, bike]} convert
I need to hash (MD5) all the password in our Sql Server 2000 database.
I need to submit a hash of attributes directly from the form tag. Is
I need to fire a hash change event more than once per tick. My
I need to create a new Hash object using two arrays. But, the conditions
I need to create a keyed hash for a string of XML to send
I need to create a perfect hash for a list of string identifiers, so
I need to convert keys from type string to hash. The name of all
Hi In My application I need to calcluate the md5 Hash Value for a

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.