std.traits.isBoolean

Tony tonytdominguez at aol.com
Mon Feb 19 13:07:08 UTC 2018


On Sunday, 18 February 2018 at 15:12:50 UTC, Mike Parker wrote:

> 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");
> }

Thanks!

It doesn't appear that BooleanTypeof is documented on dlang.org 
(outside of it's placement on the isBooleanType page). At least 
it isn't coming up in a "BooleanTypeOf site:dlang.org" search and 
not on the traits page:

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


More information about the Digitalmars-d-learn mailing list