Showing a user specified error message when no overloads match
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jul 26 10:30:59 PDT 2014
On Sat, Jul 26, 2014 at 05:14:44PM +0000, via Digitalmars-d-learn wrote:
> Hmmm... thinking about it, is this possible?
>
> 1. Remove the constraints to match anything.
> 2. Inside the template, have some construct that enumerates all possible
> overloads and UFCS functions that are visible at the point of instantiation.
> 3. If this set contains only the current template, use a static assert
> to print the message.
> 4. Otherwise, make the template fail to compile somehow (for example,
> evaluate a semantically invalid expression), and hope that the
> compiler will then take the other overloads into consideration
> (SFINAE).
>
> Could this work?
D does not have SFINAE.
This has been discussed before. I proposed the following solution:
- Sig constraints should match all types that the function *logically*
accepts -- even if the current implementation does not support some of
said types.
- In the function body, use a `static if` chain to implement
specializations.
- In the final else clause, do a static assert(0) with a user-friendly
error message.
T
--
In order to understand recursion you must first understand recursion.
More information about the Digitalmars-d-learn
mailing list