On Friday, 12 June 2015 at 12:20:58 UTC, Per Nordlöw wrote:
...

Destroy.

Improving compiler diagnostics for failed template instantiations would be a great start. However, template constraints in D are much more powerful and flexible than C++ concepts. As such, there are bound to be several cases in which the compiler can't provide any useful information, no matter how "smart" it may be.

In general, I think it needs to be easier for us programmers to produce our own error messages specifying why the template failed to instantiate. One trick that I use, which others have mentioned in other threads, is to use static asserts to find the exact condition that failed and print an informative error message.

Another idea I've mentioned before is to make it easy to define a "default" instance when none of the template constraints are satisfied. This would be a good place to insert some diagnostics to determine why the template instantiation failed and provide a meaningful error message.

A crude example:

    int foo(T)(T arg) if(...){ }
    int foo(T)(T arg) if(...){ }
int foo(T)(T arg) default // Used when all other instances fail
    {
        // Insert diagnostics here
        static assert(isRandomAccessRange!T, "...");
        ...
    }

Reply via email to