example4_reordering_binding_multiple_arguments.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include <iostream>
#include <functional>

void print(int a, int b, int c) {
    std::cout << "a = " << a << ", b = " << b << ", c = " << c << std::endl;
}

int main() {
    // Bind the first argument to 10, and reorder the rest
    auto printReordered = std::bind(print, std::placeholders::_3, std::placeholders::_1, std::placeholders::_2);

    printReordered(20, 30, 40);  // Outputs: a = 40, b = 20, c = 30

    return 0;
}
Back to std_bind