xxxxxxxxxx
struct IpV4Address
{
private uint ip;
alias ip this;
string toString()
{
import std.conv: to;
return to!string((ip >>> 24) & 0xFF) ~ "." ~
to!string((ip >>> 16) & 0xFF) ~ "." ~
to!string((ip >>> 8) & 0xFF) ~ "." ~
to!string(ip & 0xFF);
}
}
void main()
{
import std.format: format;
IpV4Address x;
x = 0x01020304; // 1.2.3.4
assert( x == 0x01020304 );
assert( format("%s", x) == "1.2.3.4" );
assert( format("%x", x) == "01020304" ); //format.d(4065): Expected '%s' format specifier for type 'IpV4Address'
}