Template constraints should introduce identifiers inside their scopes

jmh530 john.michael.hall at gmail.com
Thu Sep 22 19:23:41 UTC 2022


On Thursday, 22 September 2022 at 18:00:53 UTC, Paul Backus wrote:
> On Thursday, 22 September 2022 at 16:52:54 UTC, Timon Gehr 
> wrote:
>> On 21.09.22 14:32, Paul Backus wrote:
>>>>
>>>> They are not semantically the same. The first can be 
>>>> instantiated with any type and conditionally makes an output 
>>>> (it is empty otherwise), the other says it cannot be 
>>>> instantiated unless the arguments have specific properties.
>>> 
>>> If you want the semantics to match exactly you can replace 
>>> the `static if` with a `static assert` (or add `else static 
>>> assert(0);`).
>>
>> I think this is not true.
>>
> [...]
>>
>> `static assert` can give you a custom error message, but 
>> template constraints have much better overloading behavior. 
>> The two features are not comparable.
>
> In general, yes. In the context of the specific example in this 
> thread, they are the same. In any case, the difference has no 
> bearing on the main topic of discussion here, which is name 
> visibility.

I think the underlying principle is that the user generally 
expects them to behave similarly. Enhancing template constraint 
name visibility is probably a good thing on that principle. 
Figuring out some way for Timon's example to compile might also 
be good (perhaps overload sets would need an ordering to put 
templated functions with template constraints above those without 
template constraints?).


More information about the Digitalmars-d mailing list