digitalmars.D.learn - Neater enum + version
- Vladimirs Nordholm (11/11) Nov 18 2018 Currently I have something like
- Neia Neutuladh (8/11) Nov 18 2018 If you're doing it often:
- Vladimirs Nordholm (3/15) Nov 18 2018 Ah. Thank you for the example, might use that some other time.
- Jacob Carlborg (5/19) Nov 18 2018 This can be generalized by passing in the version identifier as a string...
Currently I have something like version (Posix) { enum foo = "bar"; } else { enum foo = "baz"; } Is there anyway to make it "neater"? Maybe something in one line: enum foo = version (Posix) { "posix" } : { "other" } ;
Nov 18 2018
On Sun, 18 Nov 2018 17:47:07 +0000, Vladimirs Nordholm wrote:Is there anyway to make it "neater"? Maybe something in one line: enum foo = version (Posix) { "posix" } : { "other" } ;If you're doing it often: T ifPosix(T)(T a, T b) { version (Posix) return a; else return b; } enum foo = ifPosix("posix", "other"); If it's a one-off thing, though, there's not much you can do.
Nov 18 2018
On Sunday, 18 November 2018 at 17:52:21 UTC, Neia Neutuladh wrote:On Sun, 18 Nov 2018 17:47:07 +0000, Vladimirs Nordholm wrote:Ah. Thank you for the example, might use that some other time. Thanks :)Is there anyway to make it "neater"? Maybe something in one line: enum foo = version (Posix) { "posix" } : { "other" } ;If you're doing it often: T ifPosix(T)(T a, T b) { version (Posix) return a; else return b; } enum foo = ifPosix("posix", "other"); If it's a one-off thing, though, there's not much you can do.
Nov 18 2018
On 2018-11-18 18:52, Neia Neutuladh wrote:On Sun, 18 Nov 2018 17:47:07 +0000, Vladimirs Nordholm wrote:This can be generalized by passing in the version identifier as a string and do a string mixin. -- /Jacob CarlborgIs there anyway to make it "neater"? Maybe something in one line: enum foo = version (Posix) { "posix" } : { "other" } ;If you're doing it often: T ifPosix(T)(T a, T b) { version (Posix) return a; else return b; } enum foo = ifPosix("posix", "other"); If it's a one-off thing, though, there's not much you can do.
Nov 18 2018