Oggetto _1

Segnaposto per gli argomenti sostituibili.

Sintassi

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

Osservazioni:

Gli oggetti _1, _2, ... _N sono segnaposto che rappresentano rispettivamente il primo, il secondo, ..., l'argomento Nth in una chiamata di funzione a un oggetto restituito da bind. Ad esempio, si usa _6 per specificare dove deve essere inserito il sesto argomento quando viene valutata l'espressione bind .

Nell'implementazione di Microsoft il valore di _N è 20.

Esempio

// 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