Share via


_1 オブジェクト

置き換え可能な引数のプレースホルダーです。

namespace placeholders {
  extern unspecified _1, _2, ... _M
  } // namespace placeholders (within std)

解説

_1, _2, ... _M の各オブジェクトは、bind 関数 によって返されたオブジェクトに対する関数呼び出しにおいて、それぞれ 1 番目から M 番目の引数を指定するプレースホルダーです。 bind 式が評価されるときに N 番目の引数が挿入される場所を指定するには、_N を使用します。

この実装では、M の値は 20 です。

使用例

 

// std__functional_placeholder.cpp 
// compile with: /EHsc 
#include <functional> 
#include <algorithm> 
#include <iostream> 
 
using namespace std::placeholders; 
 
void square(double x) 
    { 
    std::cout << x << "^2 == " << x * x << std::endl; 
    } 
 
void product(double x, double y) 
    { 
    std::cout << x << "*" << y << " == " << x * y << std::endl; 
    } 
 
int main() 
    { 
    double arg[] = {1, 2, 3}; 
 
    std::for_each(&arg[0], &arg[3], square); 
    std::cout << std::endl; 
 
    std::for_each(&arg[0], &arg[3], std::bind(product, _1, 2)); 
    std::cout << std::endl; 
 
    std::for_each(&arg[0], &arg[3], std::bind(square, _1)); 
 
    return (0); 
    } 
 
  

必要条件

ヘッダー: <functional>

名前空間: std

参照

関連項目

bind 関数

is_placeholder クラス