Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C+;中类似快速检查的模板功能基准测试+; 受Haskell优雅的自动生成(随机)给定实例类型的启发,例如在QuickCheck,我试图找出如何在C++中编写一个尽可能容易使用的基准框架。我想我会使用函数模板,可能会借助于C++11中的新特性,比如可变模板。我希望我只需要指定一个函数,或者更好的是指定一个函数模板和一个与函数的参数兼容的STL模板容器类型(依次是它的value\u type)_C++_Templates_Testing_Functional Programming_Benchmarking - Fatal编程技术网

C+;中类似快速检查的模板功能基准测试+; 受Haskell优雅的自动生成(随机)给定实例类型的启发,例如在QuickCheck,我试图找出如何在C++中编写一个尽可能容易使用的基准框架。我想我会使用函数模板,可能会借助于C++11中的新特性,比如可变模板。我希望我只需要指定一个函数,或者更好的是指定一个函数模板和一个与函数的参数兼容的STL模板容器类型(依次是它的value\u type)

C+;中类似快速检查的模板功能基准测试+; 受Haskell优雅的自动生成(随机)给定实例类型的启发,例如在QuickCheck,我试图找出如何在C++中编写一个尽可能容易使用的基准框架。我想我会使用函数模板,可能会借助于C++11中的新特性,比如可变模板。我希望我只需要指定一个函数,或者更好的是指定一个函数模板和一个与函数的参数兼容的STL模板容器类型(依次是它的value\u type),c++,templates,testing,functional-programming,benchmarking,C++,Templates,Testing,Functional Programming,Benchmarking,我认为,用一组不同大小的输入对函数进行基准测试与在C++11中设置和生成线程的方式有些相似。我的第一次尝试是复制线程类的构造函数,并将其转换为基准函数 template< class Function, class ...Args > inline void benchmark( Function&& f, Args&&... args ); 称为 typedef int T; typedef std::vector<T> C; pnw:

我认为,用一组不同大小的输入对函数进行基准测试与在C++11中设置和生成线程的方式有些相似。我的第一次尝试是复制
线程
类的构造函数,并将其转换为
基准
函数

template< class Function, class ...Args >
inline
void benchmark( Function&& f, Args&&... args );
称为

typedef int T;
typedef std::vector<T> C;
pnw::benchmark_container<std::sort, C>();
typedef int T;
typedef std::向量C;
pnw::benchmark_container();
然而,现在编译错误如下所示

tests/t_histogram.cpp: In function ‘void test_benchmark()’:
tests/t_histogram.cpp:56:44: error: no matching function for call to ‘benchmark_container()’
tests/t_histogram.cpp:56:44: note: candidate is:
tests/../benchmark.hpp:32:6: note: template<template<class> class Function, class Container> void pnw::benchmark_container()
tests/t_histogram.cpp:在函数“void test_benchmark()”中:
tests/t_histogram.cpp:56:44:错误:调用“benchmark_container()”时没有匹配的函数
测试/t_直方图。cpp:56:44:注:候选人是:
tests/./benchmark.hpp:32:6:注意:模板void pnw::benchmark_container()
< >我不确定C++是否能够单独处理另一个调用函数的模板参数传递函数模板。

这是正确的方法还是在C++11中不可能?我使用的是GCC-4.6。

如果需要支持“更高级”参数,则必须使用。此外,在模板中,
f::g
如果未通过
typename
限定,则将被视为一个值。因此,你应该写:

template <template <typename> class Function, typename Container>  // <--
inline void benchmark_container()
{
    Function<typename Container::iterator> f;   // <--
    ...

模板
内联void benchmark_容器(void(*func)(typename容器::迭代器,typename容器::迭代器))
{
容器c(10);
func(c.begin(),c.end());
}
基准容器(标准::分拣);
或者手动选择要使用的重载,允许传递常规函数对象:

template <typename Container, typename F>
inline void benchmark_container(const F& function)
{
    Container c (10);
    function(c.begin(), c.end());
}

benchmark_container<std::vector<int>>(std::sort<std::vector<int>::iterator>);
模板
内联空基准容器(常量F和函数)
{
容器c(10);
函数(c.begin(),c.end());
}
基准容器(标准::分拣);

QuickCheck是一个单元测试库,而不是基准测试库……如果您对其他解决方案感兴趣,请查看我的。谢谢。尽管如此,我仍然得到了一个错误:
tests/t\u直方图。cpp:56:44:错误:调用“benchmark\u container()”测试/t\u直方图时没有匹配的函数。cpp:56:44:注意:候选者是:tests/。/benchmark.hpp:32:6:注意:模板无效pnw::benchmark\u container()
我将其称为
typedef int t;typedef std::向量C;pnw::benchmark_container()极好的答案。如果我有更多的星星,我会给你;)
benchmark_container<std::sort, C>();
template <typename Container,
          void (*func)(typename Container::iterator, typename Container::iterator)>
inline void benchmark_container()
{
    Container c (10);
    func(c.begin(), c.end());
}

benchmark_container<std::vector<int>, std::sort>();
template <typename Container>
inline void benchmark_container(void (*func)(typename Container::iterator, typename Container::iterator))
{
    Container c (10);
    func(c.begin(), c.end());
}

benchmark_container<std::vector<int>>(std::sort);
template <typename Container, typename F>
inline void benchmark_container(const F& function)
{
    Container c (10);
    function(c.begin(), c.end());
}

benchmark_container<std::vector<int>>(std::sort<std::vector<int>::iterator>);