首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::bind1st

Defined in header <functional>

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%29fx.有效地打电话std::binder1st<F>(f, typename F::first_argument_type(x))...

2%29约束第二个论点fx.有效地打电话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

返回值

函数对象包装fx...

例外

%280%29

二次

代码语言:javascript
复制
#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";
}

二次

产出:

二次

代码语言:javascript
复制
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)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券