diff --git a/d1985r0.md b/d1985r0.md index 5dd27d0..fd2f0c3 100644 --- a/d1985r0.md +++ b/d1985r0.md @@ -9,6 +9,8 @@ author: email: - name: Gašper Ažman email: + - name: Colin MacLean + email: --- # Introduction @@ -431,6 +433,83 @@ select the first specialization unless an allocator object is given in which case the second specialization is selected. To select the third specialization the template arguments must be explicitly given. +## Impact on the partial specialization of NTTP templates + +It is a common pattern in C++ to use SFINAE to constrain template +parameter types: + +```cpp +template +struct A; + +template typename T, typename U> +struct A,std::enable_if_t>> +{ + // Implementation for templates with integral parameter types +}; + +template typename T, typename U> +struct A,std::enable_if_t>> +{ + // Implementation for templates with floating point parameter types +}; + +template +struct X {}; + +A> a; // Uses integral partial specialization +``` + +The covariant behavior of `template auto` allows a similar pattern +to be used for NTTPs. + +```cpp +template +struct B; + +template typename T, auto U> +struct B,std::enable_if_t>> +{ + // Implementation for templates with integral parameter types +}; + +template typename T, auto U> +struct B,std::enable_if_t>> +{ + // Implementation for templates with floating point parameter types +}; + +template +struct Y {}; + +B> b; // Uses integral partial specialization +``` + +This pattern cannot currently be used with NTTPs as `auto` behaves +contravariantly: + +```cpp +template +struct C; + +template typename T, auto U> +struct C,std::enable_if_t>> +{}; + +template +struct Z1 {}; + +template +struct Z2 {}; + +C> c1; // Error: T does not match Z1 +C> c2; // Ok: NTTP can only be `auto` +``` + +With partial specialization, covariant behavior is desired. We rely on +SFINAE to check that `T` accepts `U` and wish to accept any type of template +which can take an integral NTTP in this example. `template auto` allows +such a pattern to work without modifying the behavior of `auto`. ## Impacts on the specialization of variable templates @@ -553,5 +632,8 @@ production of this proposal. Gašper would likewise like to thank his employer, Citadel Securities Europe, LLC, for supporting his attendance in committee meetings. +Colin MacLean would also like to thank his employer, Lawrence Berkeley National +Laboratory, for supporting his ISO C++ Committee efforts. + A big thanks also to the members of the BSI C++ panel for their review and commentary.