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

Deduction guides #65

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Deduction guides #65

wants to merge 1 commit into from

Conversation

cone-forest
Copy link

@Naios

This is a real quick deduction guide implementation that worked for me but is really raw.
I am open to collaboration as I'm not at all familiar with the codebase.


What was a problem?

The code that didn't compile:

fu2::unique_function func = [](int x) -> float { return x / 2.f; };

Now compiles.

How this PR fixes the problem?

fu2::function, fu2::unique_function and fu2::function_view were template aliases which limited the CTAD.
Now all of them are kind of strong typedef'ed with addition of deduction guides.

Check lists (check x in [ ] of list items)

  • Additional Unit Tests were added that test the feature or regression
  • Coding style (Clang format was applied)

Additional Comments (if any)

I would really appreciate some CONTRIBUTING.md or any kind of guidance.

@Naios
Copy link
Owner

Naios commented Mar 15, 2025

Hi,
thank you for your contribution.
Unfortunately, adding new classes for function, unique_function and function_view that inherit from function_base could cause issues in the constructors or assignment operators of function_base, which are specialized for function_base and not for the new classes.
Is there maybe a different way to implement deduction?
Additionally, the deduction guides would have to be disabled when compiling function2 in C++14 to stay backwards compatible.

@cone-forest
Copy link
Author

I see how it could cause issues, however I think that it wouldn't.
All conversion rules still apply to these new classes so nothing changes really, does it?

To stay backwards compatible adding __cpp_deduction_guides check would do

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.

2 participants