Skip to content

Instantly share code, notes, and snippets.

Phobos の branches/devel をうまく扱うためにやった git-svn の設定
こうなるようにしたい:
% git br -a
master
remotes/branches/devel
remotes/branches/phobos-1.x
remotes/devel/applying_safe_system_trusted
remotes/devel/new-std-process
remotes/tags/...
/*
* ダミー左辺値 phony!T
*
* __traits(compiles, ...) とか typeof(...) で左辺値が必要なときに使う.
* 変数の実体は存在しないので,本当に使おうとするとリンクエラーになる.
*/
void main()
{
// alias typeof(foo( int.init)) A; // Error!
/*
* DDoc の邪魔をせず,テンプレート引数を常に「正規化形式」で受け取る.
*/
import std.typetuple : TypeTuple, NoDuplicates;
void main()
{
Foo!(int, int, int, int[], int, int[], int) foo;
/*
* プロパティかフィールドか分からないときはコンマ演算子を使う
*/
void main()
{
S s;
// s.func は関数なので,型は int でなく int()
static assert( is(typeof(s.field) == int));
import std.algorithm;
import std.exception;
import std.stdio;
import core.stdc.errno;
import core.stdc.stdlib;
void main()
{
import std.stdio;
void main()
{
auto p = &temporary!int();
auto q = &temporary!int();
auto r = &temporary!int();
assert(p != q && q != r && r != p);
writeln(p);
writeln(q);
/*
* Handle + range I/O
*
--------------------
% wine dmd -run test
Leading char = '/'
Read 1024 bytes
Read 1024 bytes
Read 1024 bytes
Read 1024 bytes
@sinfu
sinfu / gist:480554
Created July 18, 2010 17:24
D: 配列伸長でreallocが発生すると,コピーコンストラクタが呼ばれずにオブジェクトの複製が出来てしまう
void main()
{
auto a = new S[](8);
auto b = a;
a.length = 1024;
assert(a.ptr != b.ptr);
// コピーコンストラクタは呼ばれていないのに,コピーが出来てしまった!
// a[0..8] is b[0..8]
@sinfu
sinfu / gist:481761
Created July 19, 2010 18:18
D: Handle+Range (getNext) で子プロセスとパイプ通信 on Windows
/*
* Handle+Range I/O
*/
//----------------------------------------------------------------------------//
// Polymorphic range interface
//----------------------------------------------------------------------------//
interface InputRange(E)
{
@sinfu
sinfu / gist:485040
Created July 21, 2010 20:07
FreeBSD: putc_unlocked って速いの?
import std.perf;
import core.stdc.stdio;
import core.thread;
extern(C)
{
int flockfile(FILE*);
int funlockfile(FILE*);