bshoshany / thread-pool

BS::thread_pool: a fast, lightweight, modern, and easy-to-use C++17 / C++20 / C++23 thread pool library

Repository from Github https://github.combshoshany/thread-poolRepository from Github https://github.combshoshany/thread-pool

[BUG] Invalid range expression of type 'multi_future<int>'; no viable 'begin' function available

recsater opened this issue · comments

Describe the bug

Invalid range expression of type 'multi_future'; no viable 'begin' function available
image

Minimal working example

A short but complete program that can be compiled to reproduce the error. Paste the program between the two code fences. If it's too long or requires multiple files, attach the file(s) instead.

void runner1() {
  auto& pool = MultiThreader::GetPool();
  auto multi_future = pool.parallelize_loop(0, 10000, [](const int a, const int b){
    int k = 0;
    for (int i = a; i < b; ++i) {
      k += i;
    }
    return k;
  });
  int sum = 0;

  for (const int& sum_piece : multi_future) {

  }
}

Behavior

What behavior did you expect to get? What actually happened? If the code failed to compile, please include the full output of the compiler.

System information

  • CPU model, architecture, # of cores and threads: 20
  • Operating system: ubuntu 22.04
  • Name and version of C++ compiler: gcc 11.4.0
  • Full command used for compiling, including all compiler flags:
  • Thread pool library version: 3.5.0

(Please note that only the latest version of the thread pool library is supported.)

Additional information

Include any additional information here.

I should use multi_future.get()

Thanks for opening this issue, I'm glad you managed to solve it on your own!