I want to pass the standardized C++ binary functions to a template function, but somehow I didn't get it to work.
The following is my attempt to do it:
template<template <typename> typename Pred,typename T, typename Iterator> void iota_stepa(Iterator begin, Iterator end, T startofSequence_, T threadStep) { int currMaxThreads = startofSequence_; bool first = true; generate(begin, end, Pred<T>(currMaxThreads, threadStep) ); } and testing it with:
vector<int> tempVect_(10, 0); iota_stepa<std::plus>(begin(tempVect_),end(tempVect_),1,thread::hardware_concurrency()); gives me unfortunately the errors:
Severity Code Description Project File Line Suppression State Error C2440 '<function-style-cast>': cannot convert from 'initializer list' to 'std::plus<int>' Error C2672 'generate': no matching overloaded function found FractalCarpet Error C2780 'void std::generate(_FwdIt,_FwdIt,_Fn0)': expects 3 arguments - 2 provided FractalCarpet The console output looks like the following:
1> c:\users\mtunca\documents\esd\sps\fractalcarpet\main.cpp(55): note: see reference to function template instantiation 'void iota_stepa<std::plus,int,std::_Vector_iterator<std::_Vector_val<std::_Simple_types<float>>>>(Iterator,Iterator,T,T)' being compiled 1> with 1> [ 1> Iterator=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<float>>>, 1> T=int 1> ] 1>c:\users\mtunca\documents\esd\sps\fractalcarpet\main.cpp(34): error C2672: 'generate': no matching overloaded function found 1>c:\users\mtunca\documents\esd\sps\fractalcarpet\main.cpp(34): error C2780: 'void std::generate(_FwdIt,_FwdIt,_Fn0)': expects 3 arguments - 2 provided 1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(1532): note: see declaration of 'std::generate' Could someone help me, how to solve this problem?
Tresolved as float if bothstartofSequenceandthreadStepare integral (intandunsigned int)? I can't quite reproduce it. As for theC2780- yourstd::plusconstructor seems wierd, why are you passing parameters to it?iota_stepaand just give it a template type likeFunc. That way you can pass other "functions" like lambdas.Pred<T>(currMaxThreads, threadStep)to generate?generateexpects a function that takes no parameters and returns a value when called. You are going to have to pass something that behaves like that to it.generatetakes a function of no parameters which returns the "next" element. An instance ofstd::plusadds two numbers. You might get better help if you described the problem you're trying to solve rather than the problem you encountered while trying to solve it.