[英]bind1st and bind2nd
bind1st
binds the first argument (eg you have foo(int a, int b)
, then bind1st(foo, 1)(bar)
will be equivalent to foo(1, bar)
), bind2nd
the second one. bind1st
绑定第一个参数(例如,您有foo(int a, int b)
,然后bind1st(foo, 1)(bar)
将等同于foo(1, bar)
), bind2nd
第二个。 Don't use them, though, they're nigh useless — use generalised boost::bind
instead (or std::bind
in C++0x).但是,不要使用它们,它们几乎没用——使用广义
boost::bind
代替(或 C++0x 中的std::bind
)。
Assume you have a function object f(x,y)
and an algorithm that needs a functoid with just one variable.假设您有一个 function object
f(x,y)
和一个只需要一个变量的 functoid 的算法。 Then there's two possibilities:那么有两种可能:
y
and let the algorithm work on x
y
设置一些固定值并让算法在x
上工作x
and let the algorithm work on y
x
设置一些固定值并让算法在y
上工作That's the difference.这就是区别。
bind1st binds the first parameter of a function while bind2nd binds the second parameter. bind1st 绑定 function 的第一个参数,而 bind2nd 绑定第二个参数。 if do operation like plus() functor it will make no difference as addition of two numbers remains same in both the cases, but if u do operation like minus(), then it make difference depending upon u use bind1st or bind2nd, example 5-4 and 4-5 will generate different results, now u got the difference between bind1st first parameter binding and bind2nd second parameter binding.
如果像 plus() 仿函数一样进行操作,则不会有任何区别,因为在两种情况下,两个数字的加法都保持不变,但是如果您进行像 minus() 这样的操作,那么它会有所不同,具体取决于您使用 bind1st 或 bind2nd,例如 5- 4 和 4-5 会产生不同的结果,现在你得到了 bind1st 第一个参数绑定和 bind2nd 第二个参数绑定之间的区别。
That's obvious.这很明显。 The
bind1st
binds a value to the first operand of a functor (assuming you know what a functor in C++ is), bind2nd
to the second. bind1st
将值绑定到函子的第一个操作数(假设您知道 C++ 中的函子是什么), bind2nd
到第二个。 But for commutative operators as +
(or std::plus
) it actually makes no difference (if you didn't overload +
with non-commutative behaviour in that example).但是对于作为
+
(或std::plus
)的交换运算符,它实际上没有区别(如果你没有在该示例中使用非交换行为重载+
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.