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
struct S(T...){} | |
// void foo(T : S!U, U...)(T s) {} // DMD ICE | |
void foo(T)(T s) if(is(T Unused == S!U, U...)) {} | |
void main() | |
{ | |
S!int s; | |
foo(s); | |
} |
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
ReturnType!func checkGl(alias func, Args...)(Args args) { | |
debug scope(success) { | |
GLenum error_code = glGetError(); | |
if(error_code != GL_NO_ERROR) { | |
stderr.writefln(`OpenGL function "%s" failed: "%s."`, func.stringof, gl_error_string(error_code)); | |
} | |
} | |
return func(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 std.stdio; | |
void initOnce(alias var)(lazy typeof(var) init) | |
{ | |
static bool hasInitialised = false; | |
if(!hasInitialised) | |
{ | |
var = init(); | |
hasInitialised = true; |
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.stdio; | |
import std.format; | |
import std.array; | |
void main() | |
{ | |
ubyte[] data = [0xAA, 0xFF]; | |
auto app = appender!string(); |
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
auto values(Elems...)(auto ref Elems elems) if(is(CommonType!Elems)) | |
{ | |
alias CommonType!Elems ElemType; | |
static struct StaticArray | |
{ | |
ElemType[Elems.length] data = void; | |
size_t i = 0; | |
bool empty() const |
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.exception : onOutOfMemoryError; | |
import core.stdc.stdlib : malloc, free; | |
import std.conv : emplace; | |
T alloc(T, Args...)(auto ref Args args) if(is(T == class)) | |
{ | |
enum size = __traits(classInstanceSize, T); | |
if(auto p = malloc(size)) | |
{ |
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.typecons : Tuple; | |
import std.typetuple : TypeTuple; | |
template NameTypePairs(alias front, vars...) | |
{ | |
private enum name = __traits(identifier, front); | |
private alias pair = TypeTuple!(typeof(front), name); | |
static if(vars.length == 0) | |
alias NameTypePairs = pair; |
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
// Could use `alias front` instead to bind to single characters as well | |
mixin template DeclareVars(T, string front, names...) | |
{ | |
mixin("T " ~ front ~ ";"); | |
static if(names.length > 0) | |
mixin DeclareVars!(T, names); | |
} | |
struct S |
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
#!/usr/bin/env rdmd | |
/** | |
* Output a makefile-compatible list of source files | |
* given a list of directories containing the files. | |
* Example: | |
* ./list_sources.d src util >> Makefile | |
*/ | |
import std.algorithm, std.path; | |
// returns range of file paths |
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
mixin template ExceptionConstructor() | |
{ | |
@safe pure nothrow | |
this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) | |
{ | |
super(msg, file, line, next); | |
} | |
} | |
mixin template ExceptionConstructor(string defaultMessage) |