Feedback on Átila's Vision for D

Atila Neves atila.neves at
Wed Oct 16 11:08:18 UTC 2019

On Wednesday, 16 October 2019 at 07:09:38 UTC, JN wrote:
> On Tuesday, 15 October 2019 at 16:17:57 UTC, Atila Neves wrote:
>> Meh:
>> //C++20 concepts
>> concept isAddable = requires (T x) { x + x; };
>> // D
>> enum isAddable(T) = is(typeof((T x) => x + x));
>> We lose by one character ;)
> I disagree. It's not just one character. C++ example is much 
> cleaner. Imagine not being experienced with C++ and D and 
> seeing these two examples.


enum requires(alias F) = is(typeof(F));
enum isAddable(T) = requires!((T x) => x + x);
static assert(isAddable!int);

> C++ line of thought: we're defining a concept isAddable, which 
> is something that requires that there is some x that can be 
> added to itself.

I don't see the difference in D.

> D line of thought: we're defining an enum (why enum? why would 
> I want an enumeration here?) isAddable of type T which is 
> something that is a typeof (wait, why do I have to repeat the T 
> here again)?? What does that even mean "is(typeof())"?
> It feels more complicated for a bystander. Actually, 
> __traits(compiles) would be even cleaner in this case, because 
> the is(typeof()) part, while could be considered a D idiom, 
> feels very unexpected.

Valid point on `is(typeof)`, but as seen above easy to fix. I 
don't agree on `enum` though, because that's D syntax that's 
extremely unlikely to change.

More information about the Digitalmars-d mailing list