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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:33:02+00:00 2026-05-31T01:33:02+00:00

I want to use boost::bind to create a boost::function inserting a new key-value pair

  • 0

I want to use boost::bind to create a boost::function inserting a new key-value pair into a boost::unoredered_map but I got few compilation errors.

typedef boost::unordered_map< 
        std::string, std::string > dict_type;


inline void insert( const std::string& key, const std::string& value ){

    typedef std::pair<dict_type::iterator, bool> out_type;

    dict_type::value_type to_insert(key,value);

    boost::function<void()> f = boost::bind<out_type>( 
        &dict_type::insert
        ,obj_
        ,boost::cref(to_insert)
    );
}

The error below looks like bind cannot find the right overload for unordered_map::insert. In this case I specify exactly the right overload but this time it doesn’t work. Do you know what it is?

 ../include2/llve_clorder_id.h:32: error: no matching function for call to 
'bind(<unresolved overloaded function type>,
 boost::unordered_map<std::basic_string<char, std::char_traits<char>, 
 std::allocator<char> >, std::basic_string<char, std::char_traits<char>, 
 std::allocator<char> >, boost::hash<std::basic_string<char, std::char_traits<char>,   
 std::allocator<char> > >, std::equal_to<std::basic_string<char, std::char_traits<char>, 
 std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, 
 std::char_traits<char>, std::allocator<char> >, std::basic_string<char, 
 std::char_traits<char>, std::allocator<char> > > > >&, const 
 boost::reference_wrapper<const std::pair<const std::basic_string<char, 
 std::char_traits<char>, std::allocator<char> >, std::basic_string<char, 
 std::char_traits<char>, std::allocator<char> > > >)'
  • 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-31T01:33:04+00:00Added an answer on May 31, 2026 at 1:33 am

    The problem is that boost::unordered_map contains more than one insert, so &dict_type::insert is ambiguous. The simplest solution is to define a function to call the correct overload:

    void insert(dict_type & dict, dict_type::value_type const & value) {
        dict.insert(value);
    }
    
    boost::function<void()> f = boost::bind( 
        insert
        ,boost::ref(obj_)
        ,boost::cref(to_insert)
    );
    

    or you could specify the overload explicitly:

    boost::function<void()> f = boost::bind( 
        static_cast<out_type (dict_type::*)(dict_type::value_type const &)>(&dict_type::insert)
        ,obj_
        ,boost::cref(to_insert)
    );
    

    In C++11, you can avoid the problem with a lambda:

    std::function<void()> f = [&](){obj_.insert(to_insert);};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use boost::bind with the std::sort function. I want to bind sort
I want to use boost::crc so that it works exactly like PHP's crc32() function.
We use Boost statically linked with our app but now I want to use
I want to use boost::asio but I don't want boost to throw exceptions, because
I want to use a boost::function and pass it to a function to function
I want to use boost::thread_specific_ptr but need to know what to add to my
I want to use boost::bind (I'm not sure if it is really the right
I want to use boost::any to store heterogeneous function pointers. I get an exception
Now I am try to use boost bind & mem_fn . But there's a
I am using boost build in my project and now i want to use

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.