Skip to content

Replace uses of SFINAE with concept/requires based equivalents [NFC]#204

Merged
barche merged 6 commits into
JuliaInterop:mainfrom
halleysfifthinc:sfinae-to-concepts
May 26, 2026
Merged

Replace uses of SFINAE with concept/requires based equivalents [NFC]#204
barche merged 6 commits into
JuliaInterop:mainfrom
halleysfifthinc:sfinae-to-concepts

Conversation

@halleysfifthinc
Copy link
Copy Markdown
Contributor

@halleysfifthinc halleysfifthinc commented May 4, 2026

Aside from the first commit1, each commit replaces independent instances of the SFINAE
pattern with named concepts and/or requires statements. I find that concepts/requires
are much more directly readable and easier to reason about, but I completely understand if
the code churn isn't worth it.

Footnotes

  1. 29c435c removes a remnant C++17 flag which is no longer correct, as libcxxwrap is
    documented as having a minimum standard of C++20. (Setting the compilation flag manually
    bypasses the CMake functionality that should've prevented this.) I strengthened min
    standard requirement by adding a check in the headers. That check also protects
    non-CMake consumers of libcxxwrap, because the C++20 requirement in the CMake config is
    imposed within CMake, and not at a header/shared library level.

The CMake config has C++20 as part of the public interface, but that
only protects against normal, by-the-book CMake machinery. Setting
compilation flags manually bypasses those checks. So, also add a header
guard to completely prevent compilation using previous standards.

MSVC forces the header guard check to be more complex than it should be:
MSVC only correctly sets the `__cplusplus` value if an additional
(non-default) compile option `/Zc:__cplusplus` is set; `_MSVC_LANG`
always contains the standard value.
The concept definition combines the previous SFINAE checks that
`detail::has_call_operator<LambdaT>::value && !std::is_member_function_pointer_v<LambdaT>`
@barche
Copy link
Copy Markdown
Contributor

barche commented May 11, 2026

Thanks, this seems much simpler. Any idea what version of GCC would be required for this to compile?

@halleysfifthinc
Copy link
Copy Markdown
Contributor Author

Looking at the GCC C++ standards page, GCC 10 is when support for concepts landed.

This allows GCC 10.2 to compile the code.
@barche
Copy link
Copy Markdown
Contributor

barche commented May 23, 2026

I tested with GCC 10.2 with BinaryBuilder (what is currently used by the Yggdrasil build script) and I needed to lower the minimum version in the check. This allows us to continue to use the same GCC version, which means that once this is merged it can be distributed as a minor version update.

@barche barche merged commit 373a474 into JuliaInterop:main May 26, 2026
11 checks passed
@halleysfifthinc halleysfifthinc deleted the sfinae-to-concepts branch May 27, 2026 00:35
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