This file contains hidden or 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.regex; | |
immutable string[string] namedEntities; | |
// Construct AA at startup | |
shared static this() | |
{ | |
namedEntities = [ | |
"gt": ">", | |
"lt": "<", |
This file contains hidden or 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
private template isAttribute(Attribute) | |
{ | |
enum isAttribute(alias other) = is(typeof(other) == Attribute); | |
enum isAttribute(Other) = is(Other == Attribute); | |
} | |
private template isAttribute(alias Attribute) | |
{ | |
enum isAttribute(alias other) = is(typeof(other) == Attribute!Args, Args...); | |
enum isAttribute(Other) = is(Other == Attribute!Args, Args...); |
This file contains hidden or 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 core.time, std.algorithm, std.range, | |
std.string, std.net.curl, std.regex; | |
import std.stdio : stderr, stdout; | |
immutable usage = `%s <URL to HTML page>`; | |
enum StatusCode | |
{ | |
success = 0, |
This file contains hidden or 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
/** | |
Type constructor for final variables. | |
A final variable is "head-const"; it cannot be directly | |
mutated or rebound, but references reached through the variable | |
are typed with their original mutability. | |
*/ | |
struct Final(T) | |
if(!is(T == const) && !is(T == immutable)) | |
{ |
This file contains hidden or 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
module std.container.sortedcontainer; | |
import std.stdio; | |
import std.array : empty, front, popFront; | |
import std.range : ElementType, SortedRange, assumeSorted, hasAssignableElements, isInputRange, isRandomAccessRange; | |
// SortedRange should really support this | |
private auto internalLowerBound(Range, alias pred, T)(SortedRange!(Range, pred) range, T x) | |
if(is(T : ElementType!Range)) |
This file contains hidden or 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.algorithm, std.container, std.uni; | |
struct S | |
{ | |
string str; | |
int opCmp(const S other) const | |
{ | |
return icmp(str, other.str); | |
} |
This file contains hidden or 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.traits; | |
import std.range; | |
E[] removeSpan(E)(E[] arr, size_t from, size_t to) @trusted | |
if (isMutable!E && !hasElaborateAssign!E) | |
{ | |
import core.exception : RangeError; | |
import core.stdc.string : memmove; | |
import std.exception : enforceEx; |
This file contains hidden or 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 rand = std.random; | |
import std.traits; | |
E uniform(E, RNG)(ref RNG rng) | |
if (is(E == enum) && rand.isUniformRNG!RNG) | |
{ | |
static if (is(E B == enum)) | |
alias BaseType = B; | |
else | |
static assert(false); |
This file contains hidden or 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
interface IDisposable | |
{ | |
void dispose(); | |
} | |
auto using(T : IDisposable, CtorArgs...)(auto ref CtorArgs ctorArgs) | |
if(is(T == class) && __traits(compiles, new T(ctorArgs))) | |
{ | |
static struct Result | |
{ |
This file contains hidden or 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
// Takes instances of `Foo` | |
struct Foo(T){ T t; } | |
string takesFoo(T)(T t) if(is(T == Foo!U, U)) | |
{ | |
static if(is(T == Foo!U, U)) | |
return U.stringof; | |
else | |
static assert(false); |