No need for version expression is a lie
Kagamin
spam at here.lot
Mon Aug 28 05:57:11 UTC 2023
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:
>
> ```D
> 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");
}
```
More information about the Digitalmars-d
mailing list