Я не следующую программу, компилировать + работать, никаких проблемНе удалось шаблон <typename> определить тип указателя?
#include <thread>
#include <future>
#include <iostream>
#include <algorithm>
void f(int* first,
int* last,
std::promise<int> accumulate_promise)
{
int sum = std::accumulate(first, last, 0);
accumulate_promise.set_value(sum); // Notify future
}
int main()
{
int numbers[] = { 1, 2, 3, 4, 5, 6 };
std::promise<int> accumulate_promise;
std::future<int> accumulate_future = accumulate_promise.get_future();
std::thread work_thread(f, begin(numbers), end(numbers),
std::move(accumulate_promise));
accumulate_future.wait(); // wait for result
std::cout << "result=" << accumulate_future.get() << '\n';
work_thread.join(); // wait for thread completion
}
Но если я изменю "F" в шаблон:
template<typename Iterator>
void f(Iterator first,
Iterator last,
std::promise<int> accumulate_promise)
{
int sum = std::accumulate(first, last, 0);
accumulate_promise.set_value(sum); // Notify future
}
Тогда он не компиляции, GCC отчет, что нить :: нить() т х р не может найти правильную перегрузку: ошибки: нет подходящей функции для вызова 'станд :: Thread :: нить (, INT *, Int *, станд :: remove_reference &> :: типа)'
Что это сообщение, указывающее, anyt Неправильный шаблон с моим шаблоном? Как это исправить?
Спасибо.