Created
January 10, 2015 23:08
-
-
Save Laeeth/4119e266bd6d89a285f0 to your computer and use it in GitHub Desktop.
writeup on endswith
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
import std.array; | |
import std.string; | |
import std.stdio; | |
import std.range; | |
uint endsWithAny(alias pred = "a == b", Range, Needles)(Range haystack, Needles needles) | |
if (isBidirectionalRange!Range && isInputRange!Needles && | |
is(typeof(.endsWith!pred(haystack, needles.front)) : bool)) | |
{ | |
foreach (i, e; needles) | |
if (endsWith!pred(haystack, e)) | |
return i + 1; | |
return 0; | |
} | |
void main() { | |
import std.stdio, std.array, std.string, std.typetuple; | |
alias test = TypeTuple!("1", "two", "three!"); | |
auto b = "arghtwo".endsWith(test[]); | |
b.writeln; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment