共用方式為


_1 物件

可取代引數的預留位置。

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

備註

_1, _2, ... _M 物件是在對 bind 函式 所傳回之物件的函式呼叫中分別指定第一個、第二個、…、第 M 個引數的預留位置。 您可以使用 _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 類別