0

我需要优化BlkSize_stxxl 向量的块大小参数,以便使用简单的网格搜索来查找部分和。由于为 stxxl 向量指定它的唯一方法似乎是将其用作向量生成器中的模板参数,我知道我想使用一些递归模板函数,该函数将在给定块大小模板参数的情况下输出 partial_sum 函数使用的时间。我还需要携带矢量大小作为参数。

这是我的代码:

template<unsigned int size>
void TestPartialSum(int N) {
  typedef stxxl::VECTOR_GENERATOR<
          int,
          1,
          1, 
          size,
          stxxl::RC,
          stxxl::lru>::result xxlvector;

  xxlvector v(N);
  xxlvector res(N);
  iota(v.begin(), v.end(), 5, 2);
  std::cerr << "N = " << N <<  std::endl;
  Profiler profiler;
  std::partial_sum(v.begin(), v.end(), res.begin());
  TestPartialSum<size / 2>(N);
  return;
}

但是虽然struct stxxl::VECTOR_GENERATOR正好需要 6 个参数 ( class Tp_, unsigned int PgSz_, unsigned int Pages_, unsigned int BlkSize_, class AllocStr_, stxxl::pager_type Pager_),但我收到了这个:

error: too few template-parameter-lists

为一条typedef线。

可能是什么问题呢?

4

1 回答 1

2

看起来您缺少 atypename来告诉它result是一种类型:

  typedef typename stxxl::VECTOR_GENERATOR<
          int,
          1,
          1, 
          size,
          stxxl::RC,
          stxxl::lru>::result xxlvector;

的解释result取决于size代码中的模板参数,C++ 中有一条特殊规则将其解释为非类型,除非使用typename关键字。请参阅我必须在哪里以及为什么必须放置“模板”和“类型名称”关键字?了解更多信息。

于 2013-09-30T11:07:25.427 回答