ccia_code_samples
ccia_code_samples copied to clipboard
Listing 8.3 - Compiler Error
Issues
- Two headers are missing (
<numeric>
and<functional>
) - Our
std::packaged_task
is constructed incorrectly (requires extra parentheses) - The default constructor for
accumulate_block
is mistakenly called in place ofaccumulate_block<Iterator,T>::operator()
Stylistically it might also be nice to replace lines 50-51... https://github.com/anthonywilliams/ccia_code_samples/blob/6e7ae1d66dbd2e8f1ad18a5cf5c6d25a37b92388/listings/listing_8.3.cpp#L50-L51 ... with a range-based for loop.
for (auto &t : threads) { t.join(); }
Tested successfully on gcc, clang and apple clang.