Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 15, 2014 template constraint diagnostics | ||||
---|---|---|---|---|
| ||||
http://youtu.be/qwXq5MqY2ZA?t=33m57s I wish we had diagnostics like that in D. |
October 16, 2014 Re: template constraint diagnostics | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | Same here. I've been thinking of a DIP for a while, just haven't had time to put it together.
Atila
On Wednesday, 15 October 2014 at 17:29:35 UTC, Trass3r wrote:
> http://youtu.be/qwXq5MqY2ZA?t=33m57s
>
> I wish we had diagnostics like that in D.
|
October 16, 2014 Re: template constraint diagnostics | ||||
---|---|---|---|---|
| ||||
Posted in reply to Atila Neves | On 10/16/14 4:21 AM, Atila Neves wrote:
> Same here. I've been thinking of a DIP for a while, just haven't had
> time to put it together.
>
> Atila
>
> On Wednesday, 15 October 2014 at 17:29:35 UTC, Trass3r wrote:
>> http://youtu.be/qwXq5MqY2ZA?t=33m57s
>>
>> I wish we had diagnostics like that in D.
>
It would be nice.
I don't think it would be too difficult. You are analyzing an expression that evaluates to false, and it wouldn't take much to dig down to find out which subexpressions cause the false to occur.
-Steve
|
October 16, 2014 Re: template constraint diagnostics | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | > I don't think it would be too difficult. You are analyzing an expression that evaluates to false, and it wouldn't take much to dig down to find out which subexpressions cause the false to occur.
I think it's not that straightforward in dmd as it simply delegates the constraint to the interpreter and uses the resulting bool.
|
October 16, 2014 Re: template constraint diagnostics | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r Attachments: | On Thu, 16 Oct 2014 21:12:16 +0000
Trass3r via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> I think it's not that straightforward in dmd as it simply delegates the constraint to the interpreter and uses the resulting bool.
as there is no parallel execution, evaluator can store results in expression objects. and then simple visitor can do what it wants with this results.
|
October 17, 2014 Re: template constraint diagnostics | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar Attachments: | Am Fri, 17 Oct 2014 00:18:08 +0300 schrieb ketmar via Digitalmars-d <digitalmars-d@puremagic.com>: > On Thu, 16 Oct 2014 21:12:16 +0000 > Trass3r via Digitalmars-d <digitalmars-d@puremagic.com> wrote: > > > I think it's not that straightforward in dmd as it simply delegates the constraint to the interpreter and uses the resulting bool. > as there is no parallel execution, evaluator can store results in expression objects. and then simple visitor can do what it wants with this results. ketmar gtfo ... oh wait, that's a great idea actually! -- Marco |
October 17, 2014 Re: template constraint diagnostics | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marco Leise Attachments: | On Fri, 17 Oct 2014 08:00:03 +0200
Marco Leise via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> ketmar gtfo ... oh wait, that's a great idea actually!
;-)
|
October 17, 2014 Re: template constraint diagnostics | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Friday, 17 October 2014 at 13:22:26 UTC, ketmar via
Digitalmars-d wrote:
> On Fri, 17 Oct 2014 08:00:03 +0200
> Marco Leise via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
>
>> ketmar gtfo ... oh wait, that's a great idea actually!
> ;-)
it is! ketmar ctfb
|
October 18, 2014 Re: template constraint diagnostics | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | On 2014-10-15 17:29:33 +0000, Trass3r said: > http://youtu.be/qwXq5MqY2ZA?t=33m57s > > I wish we had diagnostics like that in D. I have answered your call: https://github.com/D-Programming-Language/phobos/pull/2627 Please comment. -S. |
October 19, 2014 Re: template constraint diagnostics | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shammah Chancellor | On 2014-10-18 21:52:30 +0000, Shammah Chancellor said:
> On 2014-10-15 17:29:33 +0000, Trass3r said:
>
>> http://youtu.be/qwXq5MqY2ZA?t=33m57s
>>
>> I wish we had diagnostics like that in D.
>
> I have answered your call:
>
> https://github.com/D-Programming-Language/phobos/pull/2627
>
> Please comment.
>
> -S.
I don't know if anyone looked at this yet, but I've updated it quite a bit since the original post. Please take a look again and comment. It also generates some useful DDoc now.
Docs:
bool isConcept(T, C, bool diagnostics = false, string errorPrefix = "")();
Returns true if T supports the concept C. Note, templated member functions are not supported currently.
Concepts should be defined as in the following example:
----
class CInputRange(E) : Concept
{
abstract void popFront();
@property abstract E front();
bool empty;
//Optional Axioms function. This will be checked if it compiles, and that it returns true if it does.
static bool Axioms(T)()
{
return true;
}
}
class CInfinite() : Concept
{
static bool Axioms(T)() {
enum empty = T.empty;
return !empty;
}
}
class CInfiniteInputRange(E) : CInputRange!E
{
mixin CInfinite;
}
---
template conceptDiagnostic(R, string F, int L, C...)
Prints error messages for why template instantiation failed.
Examples:
---
bool DoStuff(R)(R infRange) if ( isConcept!(R, CInfiniteInputRange!string))
{
return true;
}
bool DoStuff(R)(R infRange) if ( isConcept!(R, COutputRange!string))
{
return true;
}
//Example of using conceptDiagnostic
bool DoStuff(R, string F = __FILE__, size_t L = __LINE__ )(R infRange)
{
mixin conceptDiagnostic!(R, F, L, COutputRange!string, CInfiniteInputRange!string);
return false;
}
---
class Concept;
Base class for Concepts. All Concepts should derive from this, or another concept.
|
Copyright © 1999-2021 by the D Language Foundation