Re: Type sniffing at runtime

2020-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 5/15/20 11:12 PM, Alex wrote:     static if(__traits(compiles, T.min))     writeln("Minimum value  : ", T.min); A little improvement: static if(__traits(isFloating, T)) { writeln("Minimum value : ", -T.max); } else { writeln("Minimum value : ", T.min); }

Re: Type sniffing at runtime

2020-05-16 Thread Alex via Digitalmars-d-learn
On Saturday, 16 May 2020 at 05:22:49 UTC, n0den1te wrote: [...] For example, like this: ´´´ import std; alias types = AliasSeq!( bool, byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real, char, wchar, dchar ); void main() { static foreach(type; types) {

Type sniffing at runtime

2020-05-15 Thread n0den1te via Digitalmars-d-learn
Hi, I am working through the book 'Programming in D' and wanted to take the sample program on http://ddili.org/ders/d.en/types.html, one step further: import std.stdio; void main() { writeln("Type : ", int.stringof); writeln("Length in bytes: ",