Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(exercise): replace std::result_of with std::invoke_result since the old one is deprecated in C++20;#273

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Q-Wednesday wants to merge1 commit intochangkun:master
base:master
Choose a base branch
Loading
fromQ-Wednesday:deprecate_result_of

Conversation

Q-Wednesday
Copy link

@Q-WednesdayQ-Wednesday commentedOct 30, 2023
edited
Loading

Description

refer tohttps://en.cppreference.com/w/cpp/types/result_of , std::result_of was deprecated since C++ 20

When I build the exercise code with following clang++:

─╯Apple clang version 14.0.3 (clang-1403.0.22.14.1)Target: arm64-apple-darwin23.0.0Thread model: posixInstalledDir: /Library/Developer/CommandLineTools/usr/bin

I got error:

clang++ main.cpp -o main.out -std=c++2a -pedanticIn file included from main.cpp:19:./thread_pool.hpp:99:39: error: no type named 'result_of' in namespace 'std'    using return_type = typename std::result_of<F(Args...)>::type;                        ~~~~~~~~~~~~~~^~~~~~~~~./thread_pool.hpp:99:48: error: expected ';' after alias declaration    using return_type = typename std::result_of<F(Args...)>::type;                                               ^                                               ;./thread_pool.hpp:102:53: error: use of undeclared identifier 'return_type'    auto task = std::make_shared<std::packaged_task<return_type()>>(                                                    ^./thread_pool.hpp:102:53: error: template argument for template type parameter must be a type    auto task = std::make_shared<std::packaged_task<return_type()>>(                                                    ^~~~~~~~~~~~~/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/future:1558:20: note: template parameter is declared here    template <class> friend class packaged_task;                   ^In file included from main.cpp:19:./thread_pool.hpp:106:17: error: use of undeclared identifier 'return_type'    std::future<return_type> res = task->get_future();                ^5 errors generated.make: *** [main.out] Error 1

Change List

  • replace the deprecated type in exercises/7/7.1

Reference

std::result_of

@@ -96,7 +97,7 @@ inline ThreadPool::ThreadPool(size_t threads): stop(false) {
template<class F, class... Args>
decltype(auto) ThreadPool::enqueue(F&& f, Args&&... args) {
// deduce return type
using return_type = typename std::result_of<F(Args...)>::type;
using return_type = typename std::invoke_result<F,Args...>::type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
using return_type =typenamestd::invoke_result<F,Args...>::type;
using return_type = std::invoke_result_t<F,Args...>;

Copy link
Owner

@changkunchangkun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think the relevant book content should also be revised as well.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@changkunchangkunchangkun left review comments

@frederick-vs-jafrederick-vs-jafrederick-vs-ja left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@Q-Wednesday@changkun@frederick-vs-ja

[8]ページ先頭

©2009-2025 Movatter.jp