共用方式為


_1 物件

可取代引數的預留位置。

語法

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

備註

物件 _1, _2, ... _N 是預留位置,分別代表第一個、第二個、...,透過 Nth 引數,分別在 對 所 bind 傳回之物件的函式呼叫中。 例如,您可以使用 _6 來指定評估運算式時 bind ,應該插入第六個引數的位置。

在 Microsoft 實作中,值為 _N 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);
    }
1^2 == 1
2^2 == 4
3^2 == 9

1*2 == 2
2*2 == 4
3*2 == 6

1^2 == 1
2^2 == 4
3^2 == 9