std::bind1st
STD::bind1,std::bind2
Defined in header | | |
---|---|---|
template< class F, class T > std::binder1st<F> bind1st( const F& f, const T& x | (1) | (until C++17)(deprecated since C++11) |
template< class F, class T > std::binder2nd<F> bind2nd( const F& f, const T& x | (2) | (until C++17)(deprecated since C++11) |
约束给定的参数x
到给定二进制函数对象的第一个或第二个参数。f
就是商店x
在结果包装中,如果调用,则传递x
的第一个或第二个参数f
...
1%29f到x.有效地打电话std::binder1st<F>(f, typename F::first_argument_type(x))...
2%29约束第二个论点f到x.有效地打电话std::binder2nd<F>(f, typename F::second_argument_type(x))...
参数
f | - | pointer to a function to bind an argument to |
---|---|---|
x | - | argument to bind to f |
返回值
函数对象包装f
和x
...
例外
%280%29
例
二次
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
int main()
{
std::vector<double> a= {0, 30, 45, 60, 90, 180};
std::vector<double> r(a.size()
double pi = std::acos(-1
std::transform(a.begin(), a.end(), r.begin(),
std::bind1st(std::multiplies<double>(), pi / 180.)
// equivalent lambda: [pi](double a){ return a*pi/180.; }
for(size_t n = 0; n < a.size( ++n)
std::cout << a[n] << " deg = " << r[n] << " rad\n";
}
二次
产出:
二次
0 deg = 0 rad
30 deg = 0.523599 rad
45 deg = 0.785398 rad
60 deg = 1.0472 rad
90 deg = 1.5708 rad
180 deg = 3.14159 rad
二次
另见
binder1stbinder2nd (until C++17)(until C++17) | function object holding a binary function and one of its arguments (class template) |
---|
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。