On Tuesday, 22 August 2023 at 22:03:41 UTC, ryuukk_ wrote:
>Since i got confused with version(linux)
and version(Linux)
, i try to limit my use of that kind of code to a strict minimum.. but sometimes it just is not possible to avoid using it
I wish it was represented as an enum, similar to how compiler do the __FILE__
But for that to work, D would need to support .enum so you wouldn't need to import anything
In D that would look like:
enum STUFF = static switch(__OS__) {
case OS.Linux:
break;
default:
break;
};
Like this?
enum OS
{
FreeBSD, Linux, NetBSD, Windows
}
OS getOs()
{
version(FreeBSD)return OS.FreeBSD;
version(linux)return OS.Linux;
version(NetBSD)return OS.NetBSD;
version(Windows)return OS.Windows;
assert(false,"unsupported OS");
}