我遇到了这个代码的问题,它表示没有匹配的函数调用次数,虽然我使用相同的数据类型且参数的数量是相同的,有人可以帮我吗? / p>
#include <iostream>
#include <iterator>
#include <random>
#include <vector>
#include<list>
#include<deque>
#include <algorithm>
#include <chrono>
#include <functional>
#include <sstream>
using namespace std;
using namespace std::chrono;
template<typename F, typename Arg, typename T>
void times(F func, Arg A, int n, T typeval) // call func(arg,n, typeval)
{
auto t1 = system_clock::now();
func(A, n, typval);
auto t2 = system_clock::now();
auto dms = duration_cast<milliseconds>(t2-t1);
cout << "f(x) took " << dms.count() << " milliseconds\n";
}
int random_gen(int& i){
default_random_engine re { std::random_device()() };
uniform_int_distribution<int> dist;
auto r= bind(dist,re);
int x =r();
return x;
//return rand();
}
string random_gen(string& s)
{
string Result; // string which will contain the result
ostringstream convert; // stream used for the conversion
convert << rand();
return convert.str();
}
template<typename SequenceContainer, typename T>
void build_cont(SequenceContainer& seq, int n, T valtype)
{
for(int i=0; i!=n; ++i) {
T gen = random_gen(valtype);
typename SequenceContainer::iterator it = find_if(seq.begin(), seq.end(), [gen] (const typename SequenceContainer::reference & val) { return gen < val; } );
seq.insert(it, gen);
}
for(auto i:seq)
cout<<i<<endl;
}
int main() {
int n=10;
vector<int> v;
list<int>ls;
deque<int> deq;
cout<<"vector of int"<<endl;
times(build_cont, v, n, 0);
// string stemp = "";
// cout<<"vector of strings"<<endl;
// build_cont(sv, n, stemp);
// cout<<"list of strings"<<endl;
// build_cont(sls, n, stemp);
// cout<<"deque of strings"<<endl;
// build_cont(sdeq, n, stemp);
//
return 0;
}
当我运行build_cont它运行得很好,但当我把它放在时间函数中时代码停止工作? 任何建议。
答案 0 :(得分:3)
您需要指定build_cont
times(build_cont<std::vector<int>, int>, v, n, 0);