2008-05-01から1ヶ月間の記事一覧

フレンド関数を使う

C++

便利さがまだよくわからない。 #include <iostream> using namespace std; class Foo { private: int i; public: Foo(int i) : i(i) {}; friend void puts(Foo foo); }; void puts(Foo foo) { cout << foo.i << endl; } int main() { Foo foo(100); puts(foo); return </iostream>…

クラスの値渡し、戻り値 その2

C++

宣言時に初期化を行わないようにしたら、また動作が変わった。 #include <iostream> using namespace std; inline void debug(const char *s, long id) { cerr << s << ":" << id << endl; } class Foo { private: int i; public: Foo(int i) : i(i) { debug("Foo::Foo</iostream>…

RVO / NRVO

C++

えーと…RVOで関数内での自動変数の生成が呼び出し元のスコープでの自動変数の生成になったりする、と。 で、関数内で変数にバインドされてても最適化してくれるのがNRVO、と。 …あってるかな?素直にポインタ使えってことかなー。

printfを使う

C++

Cの標準ライブラリはnamespace stdに定義されてるのかなぁ? #include <cstdio> int main() { printf("Hello, C++\n"); std::printf("Hello, C++\n"); }</cstdio>

link: 出力ストリームへのendlの出力と'\n'の出力との違いは何ですか。

C++

通常、ストリーム入出力はバッファリングされており、『バッファが満杯になった。』あるいは『バッファの掃き出しが指示された。』などを機会に出力が行われます。endl処理子を出力すると、改行されるだけでなく、バッファのフラッシュも行われます。 バッフ…

初期化時の代入

C++

変数初期化時の代入では、コンストラクタと代入演算子のどちらが呼ばれるのか気になったので、実験してみた。 #include <iostream> using namespace std; #define DEBUG(s) do { cerr << (s) << endl; } while(false); class Foo { private: int i; public: Foo(); Foo</iostream>…

初期化子

C++

初期化子ってコンストラクタの呼び出しなのかな? #include <iostream> using namespace std; #define DEBUG(s) do { cerr << (s) << endl; } while(false); class Bar { public: Bar(); Bar(int i); Bar(int i, int j); }; Bar::Bar() { DEBUG("Bar::Bar()"); } Bar::</iostream>…

クラスの代入とデストラクタ

C++

#include <iostream> using namespace std; #define DEBUG(s) do { cerr << (s) << endl; } while(false); class Foo { private: int i; public: Foo(); ~Foo(); int value(); }; Foo::Foo() : i(100) { DEBUG("Foo::Foo()"); } Foo::~Foo() { DEBUG("Foo::~Foo()"); }</iostream>…

共用体を使ってみる

C++

#include <cstdio> union Foo { Foo(short i); void show(); private: short i; unsigned char cs[2]; }; Foo::Foo(short i) : i(i) {} void Foo::show() { printf("l:%x h:%x\n", cs[0], cs[1]); } int main() { union { short i; unsigned char cs[2]; }; i = 0xAB</cstdio>…

れんしゅう

C++

とりあえずcURLをいじってみた。 #include <iostream> #include <curl/curl.h> #define DEBUG(s) do { cerr << (s) << endl; } while(0) using namespace std; class Curl { private: CURL *handle; string url; string buf; static size_t puts(char *ptr, size_t size, size_t nme</curl/curl.h></iostream>…

Firter: Ming/Rubyを組み込んでみる

http://storehouse.quickvps.net/firter/?id=4 とりあえず。どうしたもんかな…

いない…

ミニクジラを探していると、どんどんモチベーションが下がっていく…

screenのコピー&ペーストをWindowsのクリップボードと同期させる

Cygwinでscreenを使っているが、Windowsのクリップボードとscreenのコピペが同期したら便利かも…と思ったので少しいじってみた。 クリップボードの操作 まず、クリップボードを操作する関数を書く。 (see http://nienie.com/~masapico/api_GetClipboardData.…

Zip/Ruby 0.2.3

http://zipruby.rubyforge.org/ https://rubyforge.org/projects/zipruby/ encrypt/decryptのバグを修正 Zip::Archive.encrypt('filename.zip', 'password') Zip::Archive.decrypt('filename.zip', 'password')

Zip/Ruby 0.2.4

http://zipruby.rubyforge.org/ https://rubyforge.org/projects/zipruby/ ちまちま書き込むAPIを追加 source = %w(London Bridge is falling down) Archive.open('test.zip') do |ar| ar.add('lb.txt') do source.shift end end これでとりあえず一通りの機…