Skip to content

Instantly share code, notes, and snippets.

@zakky-dev
Created July 26, 2013 15:20
Show Gist options
  • Save zakky-dev/6089726 to your computer and use it in GitHub Desktop.
Save zakky-dev/6089726 to your computer and use it in GitHub Desktop.
コンパイルは通っているようですが何故……。
import std.array;
bool binarySearch(T)(T[] input, T value) {
if(input.empty) {
return false;
}
auto i = input.length / 2;
auto mid = input[i];
if(mid > value) return binarySearch(input[0 .. i], value);
if(mid < value) return binarySearch(input[i .. $], value);
return true;
}
unittest {
assert(binarySearch([1,3,5,7,9,11,13,15,17,19,21], 21));
assert(!binarySearch([1,3,5,7,9,11,13,15,17,19,21], 2));
}
/*
/home/zakky/dmd2/linux/bin64/../lib64/libphobos2.a(dmain2_44d_1a5.o): 関数 `main' 内:
src/rt/dmain2.d:(.text.main+0xa): `_Dmain' に対する定義されていない参照です
collect2: エラー: ld はステータス 1 で終了しました
--- errorlevel 1
*/
@zakky-dev
Copy link
Author

叩くコマンドをミスしてました。
dmd -unittest -main -run binary.d
なら大丈夫のようです。
ただしバグが仕込まれている……。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment