Compile-Time Interfaces (Concepts)

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 23 07:27:03 PDT 2014


On Wed, Jul 23, 2014 at 04:21:16PM +0200, bossfong via Digitalmars-d-learn wrote:
> Could we possibly have a template like the following:
> 
> satisfiesInterface!(T, Interface);
> 
> that would return true when T satisfies Interface and otherwise gives
> descriptive error messages via __pragma(error, ...) ?
> 
> Then isInputRange could simply use satisfiesInterface under the hood
> and user code had a nice tool to check their very own requirements.
> I'm not sure if such a template is possible though.

We could, though it's not quite the same as a native concepts
implementation where the compiler can check templates for code that
wrongly makes assumptions about the incoming type that aren't defined by
the concept.


T

-- 
I think Debian's doing something wrong, `apt-get install pesticide', doesn't seem to remove the bugs on my system! -- Mike Dresser


More information about the Digitalmars-d-learn mailing list