Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- bool foo(T)(const(char)[] id, T arg)
- if (is(T : const(char)[]) || is(T : const(char[])[]))
- {
- static if (is(T : const(char)[])) {
- return id == arg;
- } else {
- foreach (s; arg) if (s == id) return true;
- }
- return false;
- }
- */
- bool foo(const(char)[] id, const(char[])[] arg ...)
- {
- foreach (s; arg) if (s == id) return true;
- return false;
- }
- void main()
- {
- string id = "id";
- char[] a = "aaaa".dup;
- const(char)[] b = "bbbb";
- immutable(char)[] c = "cccc";
- foo(id, a);
- foo(id, b);
- foo(id, c);
- char[][] aa = ["aaaa".dup];
- const(char)[][] bb = ["bbbb"];
- immutable(char)[][] cc = ["cccc"];
- foo(id, aa);
- foo(id, bb);
- foo(id, cc);
- // these works with the typesafe variadic function only
- foo("id");
- foo("id", "aaaa", "bbbb");
- foo("id", "aaaa", "bbbbb", "cccc");
- // these should always fail
- dstring w = "wwww";
- dstring[] ww = ["wwww"];
- foo(id, w);
- foo(id, ww);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement