Why is the return type of std::bind unspecified?

2019-07-26 14:22发布

问题:

The return type of boost::bind and now std::bind is unspecified.

unspecified bind

What is the return type of boost::bind?

Why is it that the return type of boost::bind and now std::bind is unspecified? Why isn't it something like boost::function and std::function?

I realize that the intent is to refer to the return type via type deduction but that doesn't answer why std::bind is special.

If that was just the whim of the committee then ok, there's not much else to say, but is there a technical reason that specifying a return type for std::bind is uniquely burdensome or that not specifying it permits a more efficient implementation?

回答1:

Well, for starters there isn't just one return type. It varies greatly depending on the types of the arguments passed in.

The C++ Standard is leaving a lot of flexibility to implementers exactly how different cases are broken out (using overloading and SFINAE) and mapped onto different closure object types.



回答2:

It isn't boost::function or std::function because those both perform type erasure, which may need a memory allocation (bind does not) and typically cannot have the function call inlined.