Skip to content

Instantly share code, notes, and snippets.

@sinfu
sinfu / gist:489306
Created July 25, 2010 04:45
Handle+Port [試A]
import core.stdc.stdio : printf;
void main()
{
auto file = new File(__FILE__);
scope(exit) file.close;
// file に対してバイナリ入力を始める
auto binport = new BinaryInputPort(file);
@sinfu
sinfu / gist:501291
Created July 30, 2010 20:47
Schemeのマクロ好き
#!r6rs
(import (rnrs))
(define (iota-step k n s)
(if (<= s 0) (assertion-violation 'iota "non-positive step" s))
(cond ((> k n) '())
(else (cons k (iota-step (+ k s) n s)))))
(define-syntax iota
(lambda (stx)
@sinfu
sinfu / my-freebsd.mak
Created August 4, 2010 19:24
Quick hacked makefile for Phobos on FreeBSD
# Makefile to build FreeBSD D runtime library libphobos2.a and its unit test
#
# make clean => removes all targets built by the makefile
#
# make zip => creates a zip file of all the sources (not targets)
# referred to by the makefile, including the makefile
#
# make release => makes release build of the library (this is also the
# default target)
#
import std.stdio;
void main()
{
C c1, c2;
C r1, r2;
r1 = c1 = new C(1);
r2 = c2 = new C(2);
@sinfu
sinfu / rederror.d
Created August 9, 2010 17:15
赤い pragma(msg)
enum int a = ensureNonNegative!(+42); // ok
enum int b = ensureNonNegative!(-42); // error!
template ensureNonNegative(int i)
{
static if (i < 0)
mixin error!("Aiiieeeeeeeeeee! i=", i);
else
enum int ensureNonNegative = i;
@sinfu
sinfu / gist:520645
Created August 12, 2010 09:44
Uniqueのデストラクタは安全?
class Container
{
struct // Unique
{
// Unique のデストラクタ…
// これが呼ばれたとき,Unique 自身のメモリ領域 (Container のメモリ領域) は生きてる? 死んでる?
//
// 「Container のメモリ領域開放 → Unique の破棄」というシナリオはあり得る? 逆はあっても….
//
@sinfu
sinfu / gist:521127
Created August 12, 2010 15:14
構造体のconstをtailconstに弱める
struct S
{
int[] array;
int value;
R another;
}
struct R
{
int[] array;
@sinfu
sinfu / gist:522840
Created August 13, 2010 13:03
明示的フォワードでも駄目なんだね
void main()
{
enum s = S(S.F(42));
alias W!( s .a ) k3; // 'a'
// alias W!(wantValue(s .a)) k4; // Error: this for a needs to be type F not type A
alias W!( s.forward.a ) k1; // 'a'
alias W!(wantValue(s.forward.a)) k2; // '42'
}
alias W!(S .square) symA;
@sinfu
sinfu / gist:522842
Created August 13, 2010 13:05
トリアエーズ alias this
diff --git src/mtype.c src/mtype.c
index 0dadfc6..c046505 100644
--- src/mtype.c
+++ src/mtype.c
@@ -5403,6 +5403,10 @@ d_uns64 TypeQualified::size(Loc loc)
* if type, *pt is set
*/
+static Dsymbol *searchForwardedSymbol(Loc loc, Scope *sc,
+ AggregateDeclaration *aggr, Identifier *id);
enum MyObject : Object
{
init = Object.init,
}
static assert(!is(MyObject == Object));
static assert(is(MyObject : Object));
void main()