標準化されたC++バイナリ関数をテンプレート関数に渡したいのですが、どういうわけかそれは動作しませんでした。バイナリ関数をテンプレート関数に渡す方法C++
次はそれを行うには、私の試みです:
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));
}
としてそれをテスト:
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
コンソール出力は次のようになります。
vector<int> tempVect_(10, 0);
iota_stepa<std::plus>(begin(tempVect_),end(tempVect_),1,thread::hardware_concurrency());
は、エラーが、残念ながら私を与えます以下:
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'
この問題を解決する方法を教えてもらえますか?
: あなたは、おそらくこのように、ラムダと1を作成することができます。 – molbdnilo
'startofSequence'と' threadStep'の両方が整数( 'int'と' unsigned int')の場合、地球上でどのように 'T'がfloatとして解決されますか?私はそれを再現することはできません。 'C2780'について - あなたの' std :: plus'コンストラクタはwierdのようですが、なぜあなたはそれにパラメータを渡していますか? – Ap31
私は個人的に 'iota_stepa'の関数パラメータにして、' Func'のようなテンプレート型を与えます。そうすれば、ラムダのような他の "関数"を渡すことができます。 – NathanOliver