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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:35:02+00:00 2026-06-13T21:35:02+00:00

Suppose I have a function that takes two arguments, void f(int x, int y);

  • 0

Suppose I have a function that takes two arguments,

void f(int x, int y);

and I want to bind one of them. I can use std::bind as follows:

auto partiallyBoundF = std::bind(f, 10, _1);

partiallyBoundF takes only one argument, but I can call it with more than one. The arguments beyond the first don’t even have to be of a type that makes any sense:

partiallyBoundF(20, 0);
partiallyBoundF(0, 44, -99, "Hello", 4.5, true, []{});

What is the purpose of permitting objects returned from bind to be passed extra arguments? It allows calling errors to compile that would be rejected anyplace else.

  • 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-13T21:35:04+00:00Added an answer on June 13, 2026 at 9:35 pm

    Ignoring extra arguments is a lot simpler to implement, and can actually be useful.

    In a typical implementation e.g. libstdc++ (g++), the approach taken is to collect the operator() arguments into a tuple and then let the std::placeholder bind arguments extract them as required. Enforcing argument count would require counting the number of used placeholders, which would be pretty complicated. Note that the bind callable can be a functor with multiple or templated operator() call patterns, so the bind object operator() can’t be generated with a single “correct” signature.

    Also note that you can write:

    std::bind(&foo, std::placeholders::_1, std::placeholders::_3);
    

    i.e. explicitly ignoring the second argument to the bind object. If bind enforced its argument count you would need an additional way to specify that e.g. a fourth argument was also to be ignored.

    As for usefulness, consider binding a member signal handler to a signal:

    sig.connect(std::bind(&C::on_sig, this, param, std::placeholders::_1));
    

    If sig has extra unwanted emission parameters, then they are simply ignored by the bind object; otherwise, binding the same handler to multiple signals would require writing multiple forwarding wrappers for no real purpose.

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

Sidebar

Related Questions

Suppose I have a function void myFun(int*) In C++ what exactly does the following
I'm trying to write a function that takes two string arguments and returns the
Suppose I have a class with a constructor (or other function) that takes a
Suppose I have a function test <- function(s,t) { .. } that requires two
Suppose I have a function that returns a closure: sub generator { my $resource
Suppose that you have a function f: List a -> a such that f
Suppose that in the main I have a function a : a(c); and c
I have the following function that is supposed to trigger anytime one of the
Suppose I have a function defined like this: class Foo() { public: void bar(MyClass*
Suppose I have a function like this (I use akka 2.0.2): def foo(message: String):

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.