Skip to content

Listing 8.3 - Compiler Error #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ITHelpDec
Copy link

Issues

  1. Two headers are missing (<numeric> and <functional>)
  2. Our std::packaged_task is constructed incorrectly (requires extra parentheses)
  3. The default constructor for accumulate_block is mistakenly called in place of accumulate_block<Iterator,T>::operator()

Stylistically it might also be nice to replace lines 50-51...

std::for_each(threads.begin(),threads.end(),
std::mem_fn(&std::thread::join));

... with a range-based for loop.

for (auto &t : threads) { t.join(); }

Tested successfully on gcc, clang and apple clang.

Two headers needed for compilation on gcc and clang

+ #include <numeric>    // std::accumulate
+ #include <functional> // std::mem_fn

(Apple Clang only needs <numeric>)
"Parentheses were disambiguated as a function declaration"
- extra parentheses needed to call `accumulate_block<Iterator,T>::operator()` in place of default constructor

"No matching constructor for initialization of 'accumulate_block<std::__wrap_iter<int *>, int>'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant