std::bind1st, std::bind2nd
提供: cppreference.com
< cpp | utility | functional
ヘッダ <functional> で定義 | ||
template<class F, class T > std::binder1st<F> bind1st(const F& f, const T& x ); | (1) | (C++11で非推奨) (C++17で削除) |
template<class F, class T > std::binder2nd<F> bind2nd(const F& f, const T& x ); | (2) | (C++11で非推奨) (C++17で削除) |
指定された引数 x
を指定された二項関数オブジェクト f
の第1引数または第2引数に束縛します。 つまり、呼ばれた場合に f
の第1引数または第2引数として x
を渡す結果のラッパー内に x
を格納します。
1) f
の第1引数を x
に束縛する。 実質的に std::binder1st<F>(f, typename F::first_argument_type(x)) を呼びます。
2) f
の第2引数を x
に束縛する。 実質的に std::binder2nd<F>(f, typename F::second_argument_type(x)) を呼びます。
目次 |
[編集]引数
f | - | 引数を束縛する関数へのポインタ |
x | - | f に束縛する引数 |
[編集]戻り値
f
と x
をラップする関数オブジェクト。
[編集]例外
(なし)
[編集]例
Run this code
#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
[編集]関連項目
(C++11で非推奨)(C++17で削除) | 二項引数とその引数の1つを保持する関数オブジェクト (クラステンプレート) |