How to bind plus<int> and multiplies<int> and make calculation in C++

1 Answer

0 votes
#include <iostream>
#include <functional>

using std::cout;
using std::endl;

int main()
{
	auto plus5times3 = std::bind(std::multiplies<int>(), 
		               std::bind(std::plus<int>(), 
					   std::placeholders::_1, 5), 3);

	cout << plus5times3(8) << endl; // (5 + 8) * 3 = 39
}

/*
run:

39

*/

 



answered Jan 25, 2018 by avibootz

Related questions

...