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

  • SEARCH
  • Home
  • 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 8740531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:08:46+00:00 2026-06-13T11:08:46+00:00

This code compiles fine with g++ 4.4 and ‘-std=c++0x’. #include <unordered_set> namespace { size_t

  • 0

This code compiles fine with g++ 4.4 and ‘-std=c++0x’.

#include <unordered_set>

namespace
{

size_t IntHash ( int i )
{
    return i;
}

bool IntComp ( int i, int j )
{
    return i == j;
}

}

int main ( int argc, char* argv[] )
{
    typedef std::pointer_to_unary_function<int, size_t> CustomHash;
    typedef std::pointer_to_binary_function<int, int, bool>
        CustomComp;

    typedef std::unordered_set<int, CustomHash, CustomComp> DeprecatedSet;

    DeprecatedSet deprecatedSet ( 10, std::ptr_fun ( IntHash ), std::ptr_fun ( IntComp ) );

    deprecatedSet.insert ( 5 );
    deprecatedSet.insert ( 10 );
}

Say, however, I didn’t want to use the deprecated std::pointer_to_unary_function and std::ptr_fun, but still use the free functions:

#include <unordered_set>
#include <functional>

namespace
{

size_t IntHash ( int i )
{
    return i;
}

bool IntComp ( int i, int j )
{
    return i == j;
}

}

int main ( int argc, char* argv[] )
{
    typedef std::unordered_set<int /*, UserDefinedHash?, UserDefinedComparison? */> NewSet;

    NewSet newSet (
        10,
        std::bind ( IntHash, std::placeholders::_1 ),
        std::bind ( IntComp, std::placeholders::_1, std::placeholders::_2 ) );

    newSet.insert ( 5 );
    newSet.insert ( 10 );
}

This doesn’t compile, I assume because I’m not sure what to put in for UserDefinedHash and UserDefinedComparison.

It doesn’t look like std::bind has a member type defining the type of the bind object itself.

I’m aware that there’s other ways to define custom hash functions and comparisons, just curious if free/class functions can be used without deprecated standard library types and functions.

  • 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-13T11:08:47+00:00Added an answer on June 13, 2026 at 11:08 am

    You can use:

    std::unordered_set<int, size_t(*)(int), bool(*)(int, int)> my_set;
    my_set s( 10, &IntHash, &IntComp );
    

    And in order to use std::bind, you can use decltype or std::function

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

Sidebar

Related Questions

This code compiles fine with GCC and Clang but not with MSVC 2010: #include
I'm having a hard time using std::string::iterators in C++. This code compiles fine (still
I am unclear about the following. First, this code compiles fine: #include <vector> typedef
I have this problem with signal() : This code compiles fine: #include <stdio.h> #include
This code compiles fine, but when I try to run it, it fails. int
This code compiles fine: {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances, FlexibleContexts, EmptyDataDecls, ScopedTypeVariables, TypeOperators,
This Java code compiles fine, but when I try to run it I get:
I wrote this code that compiles on Solaris gcc it works fine too for
Please check this code out it compiles and runs absolutely fine.. The question is
EDIT: I realized that this code compiles and works: #include <iostream> template<class Something> class

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.