function2 icon indicating copy to clipboard operation
function2 copied to clipboard

Deduction guides

Open cone-forest opened this issue 11 months ago • 2 comments

@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.

cone-forest avatar Mar 13 '25 20:03 cone-forest

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.

Naios avatar Mar 15 '25 17:03 Naios

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

cone-forest avatar Mar 18 '25 19:03 cone-forest