Skip to content
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

Cannot use with non-copyable, non-movable return types in function signatures #20

Open
burnpanck opened this issue Feb 27, 2021 · 0 comments

Comments

@burnpanck
Copy link

In C++17 and later the new mandatory ellision of copy/move operations allow the following function:

NonCopyNonMoveType f() {
  return NonCopyNonMoveType();
}

even if NonCopyNonMoveType has neither an accessible copy constructor nor an accessible move constructor.

Given that definition of f, also the following is valid

NonCopyNonMoveType g() {
  return f();
}

However, the expression function_ref<NonCopyNonMoveType()>(f) will not compile.

The usual constructor is disabled because the requirement std::is_convertible_v<std::invoke_result_t<decltype(f)>,NonCopyNonMoveType> is not met.
That is the case because convertibility tests the possibility to construct a new function_ref return value from an rvalue of an existing return value of the supplied callable (in this case, it would be a move). However, under the new move ellision rules, no such move will actually happen. Therefore, in this case, the requirement rejects a callable that would be perfectly valid.

burnpanck added a commit to burnpanck/function_ref that referenced this issue Feb 27, 2021
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

No branches or pull requests

1 participant