Skip to content

Instantly share code, notes, and snippets.

@Laeeth
Created January 10, 2015 23:08
Show Gist options
  • Save Laeeth/4119e266bd6d89a285f0 to your computer and use it in GitHub Desktop.
Save Laeeth/4119e266bd6d89a285f0 to your computer and use it in GitHub Desktop.
writeup on endswith
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