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
struct ReadLease(T) | |
{ | |
~this() { releaseReadLease(this); } | |
const(T)* get() @property return const pure nothrow @safe @nogc { return object; } | |
alias get this; | |
private: | |
const(T)* object; | |
shared(ptrdiff_t)* leaseCounter; |
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
module visuald_test; | |
import std.stdio; | |
int main() | |
{ | |
writeln("Hello D World!\n"); | |
return 0; | |
} |
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
#include <stdio.h> | |
#include <string.h> | |
class BlockedArray | |
{ | |
static const size_t BlockSize = 1024; // how many elements should fit in a block? | |
struct Block | |
{ | |
union |
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 core.memory : pureMalloc, pureFree; | |
import object : destroy; | |
// this API supports classes and non-classes with the same functions | |
auto myAlloc(T, Args...)(auto ref Args ctorArgs) @trusted | |
{ | |
static if (is(T == class)) | |
{ | |
size_t bytes = __traits(classInstanceSize, T); // this is because classes are reference types; therefore T.sizeof == sizeof the class reference (pointer) | |
alias ReturnType = T; // classes are references, so you don't handle them by pointer |
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
enemy = { screenWidth/2, screenTop }; | |
player = { screenWidth/2, screenBottom }; | |
while(1) | |
{ | |
if(enemy.x > screenWidth) | |
v = -1; | |
else if(enemy.x < 0) | |
v = 1 | |
enemy.x += v; |
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
auto literalRange(alias value)(size_t length) | |
{ | |
struct LiteralRange(alias Value) | |
{ | |
alias value = Value; | |
size_t length; | |
@property bool empty() const { return !length; } | |
@property auto front() inout { return value; } | |
void popFront() { --length; } |