Search code examples
c++templatestypedefstxxl

Error in a recursive template function using STXXL templates in C++


I need to optimize the block size BlkSize_ parameter of the stxxl vector for partial sums finding using a simple grid search. As the only way to specify it for a stxxl vector seems to use it as a template parameter in vector generator, I understand that I want to use some recursive template function that would output time used by partial_sum function given a block size template parameter. I also need to carry a vector size as a parameter.

Here is my code:

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;
}

But though struct stxxl::VECTOR_GENERATOR takes exactly 6 parameters (class Tp_, unsigned int PgSz_, unsigned int Pages_, unsigned int BlkSize_, class AllocStr_, stxxl::pager_type Pager_), I receive this:

error: too few template-parameter-lists

for a typedef line.

What could be the problem?


Solution

  • It looks like you are missing a typename to tell that result is a type:

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

    The interpretation of result depends on the template argument size in your code, and there is a special rule in C++ to interpret it as a non-type unless the typename keyword is used. See Where and why do I have to put the “template” and “typename” keywords? for more info.