Namespaces
Variants
Views
Actions

Talk:cpp/types/enable if

From cppreference.com

Sorry, still clear as mud. Can you please offer an example of a simple template class declaration with just ONE type in the template, where the class cannot be compiled/instantiated if the type specifier in the template is not arithmetic, for instance? Preferably compare and contrast how it's done in C++11, C++14, C++17, and C++20 (where concepts are used).

Example #1 with the return type SFINAE takes just one type in the template, it uses is_trivially_default_constructible instead of is_arithmetic, both work the same way. In my experience SFINAE is generally done with enable_if as an redundant template parameter (form #4 / partial specialisation example). Nothing about SFINAE changes until C++20, at which point enable_if isn't used at all, though a "modernisation" example probably wouldn't hurt, but there's already so much code on this page, I think it's better to just link off to the concepts page.
Nonetheless, https://wandbox.org/permlink/lw4GvYqeWOIThLPP --Ybab321 (talk) 05:13, 26 December 2021 (PST)