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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:16:38+00:00 2026-06-11T07:16:38+00:00

So I’m implementing a boost::hash_value override for my class that is exported from a

  • 0

So I’m implementing a boost::hash_value override for my class that is exported from a shared library. I’d like to have that hash_value function available for everyone who uses this class. Currently my hash_value function is exported and defined in the cpp file, even though it just calls an inline member of my class. Instead, I’d like this hash_value function to also be inlined as to avoid unneeded function calls. Currently the header’s like this:

#ifdef MYDLL
#define MY_API __export
#else
#define MY_API __import
#endif

class MY_API MyGUID
{
public:
     ...
     inline size_t Hash() const
     {  return m1 ^ m2; }
     ...
private:
     size_t m1,m2;
};

namespace boost
{
    // Defined in .cpp file; just returns inGUID.Hash();
    MY_API size_t hash_value(const MyGUID &inGUID);
}

But I’d like that hash_value to be more like:

   namespace boost
    {
        // I'd like to inline this, like so:
        static inline size_t hash_value(const MyGUID &inGUID)
        { 
             return inGUID.Hash();
        }
    }

Except this code above defines hash_value in every .cpp file that includes it, quite likely littering the binary, and is ugly in principle.

Putting aside the question of whether the function calls make a measurable difference in performance, how can I get my class’ Hash function inlined for clients of this shared library that use MyGUID in hashed containers like ordered_set?

I suspect it involves templates, but I couldn’t quite figure out how.

  • 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-11T07:16:40+00:00Added an answer on June 11, 2026 at 7:16 am

    If you look inside boost/functional/hash/hash.hpp you will see that hash_value for existing types are defined like:

    inline std::size_t hash_value(bool v)
    {
        return static_cast<std::size_t>(v);
    }
    

    If boost already uses technique this is your hint that it is safe for you to do the same! Regarding your concern about inefficiencies of using inline in the header file, that is precisely how it is designed to be used and since your function is simply forwarding to another function call it will probably lead to no increase in code size at all.

    Unless you are going to be doing something very fancy with preprocessor directives it does not make much sense to use static inline, i.e., if you just need one version of this function just mark it as inline.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.