Looks very nice! I think I could make use of it. (Though I use D only recreationally :-) )

LMB


On Sun, Oct 19, 2014 at 7:10 PM, Shammah Chancellor via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
It was request that I create a NG thread about a module I was hoping to merge with phobos. (std.concepts)  Please take a look.

Thanks in advance.

-S

Link to PR:

https://github.com/D-Programming-Language/phobos/pull/2627

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.