Skip to content

Instantly share code, notes, and snippets.

@sinfu
sinfu / gist:610238
Created October 4, 2010 19:01
metaArray
struct MetaArray(seq...)
{
alias seq Expand;
// CTFE-capable
bool opEquals(rhsSeq...)(MetaArray!rhsSeq )
{
return is(MetaArray!seq == MetaArray!rhsSeq);
}
}
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
int main()
{
int fdesc = open("test-out.dat", O_RDWR | O_CREAT, 0744);
{
char store[10];
ssize_t r;
void Optionalを使って()
{
ubyte[] buf;
if (Optional!size_t r = read(buf))
{
if (r == 0)
{
// EAGAIN
}
import std.meta;
void main()
{
Struct!(int, "x", double, "y") s;
s.x = 10;
s.y = 20.35;
}
struct Struct(TypesNames...)
@sinfu
sinfu / gist:598659
Created September 27, 2010 05:32
More tuple algorithms
module meta;
@safe:
/**
*/
template StaticTuple(seq...)
{
alias seq StaticTuple;
import std.stdio;
void main()
{
auto src = Source(__FILE__);
auto buf = Buffer(src);
auto stm = TextStream(buf);
foreach (i; 1 .. 10)
{
/*
出力
0,0
1,0
2,0
3,0
*/
import std.stdio;
@sinfu
sinfu / meta.d
Created September 5, 2010 09:09
module std.meta;
// Workaround for a weird error:
// Error: "identifier 'length' of 'seq.length' is not defined"
private template staticLength_(seq...)
{
enum staticLength_ = seq.length;
}
@sinfu
sinfu / gist:564575
Created September 3, 2010 21:10
formattedWrite
import std.format;
import std.stdio;
void main()
{
formattedWrite((in char[] s)
{
writeln(">> '", s, "'");
},
"%s %s %s", 1, 2, 3);
@sinfu
sinfu / gist:547880
Created August 24, 2010 16:48
operator overloads @ interfaces
interface BinaryOperand(RHS, string op : "+")
{
BinaryOperand opAdd(RHS other);
final BinaryOperand opBinary(string op : "+")(RHS other)
{
return opAdd(other);
}
}