On Sunday, 18 February 2018 at 14:52:37 UTC, Tony wrote:
At
https://dlang.org/library/std/traits/is_boolean.html

it has:


enum isBoolean(T) = is(BooleanTypeOf!T) && !isAggregateType!T;

per:
https://dlang.org/library/std/traits/is_aggregate_type.html

isAggregateType is true for [struct, union, class, interface].

So BooleanTypeOf!T is true for structs, unions, classes and interfaces? And if yes, why is that so?

Generally, no. But with alias this, it can be:

=====
import std.traits : BooleanTypeOf;
import std.stdio : writeln;

struct NoBool {
    int x;
}

struct AliasThisBool {
    bool b;
    alias b this;
}

void main()
{
    static if(is(BooleanTypeOf!NoBool)) writeln("NoBool");
static if(is(BooleanTypeOf!AliasThisBool)) writeln("AliasThisBool");
}
=====

Reply via email to