Created
March 16, 2013 17:54
-
-
Save CyberShadow/5177509 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template Tuple(T...) { alias T Tuple; } | |
| template Select(bool b, T, U) { static if (b) alias T Select; else alias U Select; } | |
| void main() | |
| { | |
| static bool isEq (T1, T2)(T1 s1, T2 s2) { return s1 == s2; } | |
| static bool isNeq(T1, T2)(T1 s1, T2 s2) { return s1 != s2; } | |
| foreach (b1; Tuple!(false, true)) | |
| foreach (b2; Tuple!(false, true)) | |
| { | |
| assert( isEq (cast(Select!(b1, string, char[1]))"a", cast(Select!(b2, string, char[1]))"a" )); | |
| assert(!isNeq(cast(Select!(b1, string, char[1]))"a", cast(Select!(b2, string, char[1]))"a" )); | |
| assert(!isEq (cast(Select!(b1, string, char[1]))"a", cast(Select!(b2, string, char[1]))"b" )); | |
| assert( isNeq(cast(Select!(b1, string, char[1]))"a", cast(Select!(b2, string, char[1]))"b" )); | |
| assert(!isEq (cast(Select!(b1, string, char[1]))"a", cast(Select!(b2, string, char[2]))"aa")); | |
| assert( isNeq(cast(Select!(b1, string, char[1]))"a", cast(Select!(b2, string, char[2]))"aa")); | |
| // Note: order of evaluation was not followed before this patch | |
| // (thus, the test below will fail without the patch). | |
| // Although the specification mentions that as implementation-defined behavior, | |
| // I understand that this isn't by design, but rather an inconvenient aspect of DMD | |
| // that has been moved to the specification. | |
| int order = 0; | |
| auto getS1()() { assert(order==0); order++; return cast(Select!(b1, string, char[1]))"a"; } | |
| auto getS2()() { assert(order==1); order++; return cast(Select!(b2, string, char[1]))"a"; } | |
| bool result = getS1() == getS2(); | |
| assert(result); | |
| assert(order == 2); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment