C++0x

TrivialClock

C++0x の最新の仕様では、Chrono ライブラリに TrivialClock の要件が追加されています。 今までの Clock の要件に加えて、TrivialClock はほとんどの操作で例外を投げてはいけないという要件が追加されています(他にもいくつか追加されている要件がありま…

char8_t 欲しい

C++0x からは UTF16 の文字列リテラル(u"...")とその型(char16_t)、UTF32 の文字列リテラル(U"...")とその型(char32_t)が入ります。 そして UTF8 の文字列リテラル(u8"...")も入ります。しかし UTF8 を表す型は入りません。u8"..." は char の配列…

プログラミングの魔導書 〜Programmers' Grimoire〜 Vol.1

ついに出ました。 株式会社ロングゲート 自分は「Chronoライブラリで考える型システム」という題で書かせて頂きました。 内容について どんな内容かというと、ChronoというC++0xで新しく入る時間ユーティリティを通じて、型システムがいかに素晴らしいかとい…

関数のテンプレート引数を明示的に書いたかどうかで分岐する

こんな感じ。 #include <iostream> template<class T> struct identity { typedef T type; }; template<class T> void f(typename identity<T>::type) { std::cout << "type T" << std::endl; } template<class T, class... Types> void f(T, Types...) { std::cout << "deduced" << std::endl; } int main() { f<int>(10);</int></class></t></class></class></iostream>…

const_cast の仕様

まあ調べたかったのは、const_cast して未定義動作になるのはどんな場合かってだけなんだけど、ある程度翻訳したので一応載せてみる。 式 const_cast(v) の結果は T である。もし T が lvalue reference 型か function 型への rvalue reference 型である場合…

文字列リテラルの char[] 初期化

本の虫: C++0xでは、文字列リテラルから非constなポインタへの変換はできない に char* への変換はダメっていうのがありますが、char[] への変換はどうなの?という話です。 const char cs[] = "bjarne"; char s[] = "hage"; cs は当然 OK ですけど、s はど…

記録更新

C++0x では新しく allocator_traits というのが入るわけですが、このシグネチャはこうなってます。 namespace std { template <class Alloc> struct allocator_traits { typedef Alloc allocator_type; typedef typename Alloc::value_type value_type; typedef see below</class>…

プリプロセス時のユーザ定義リテラルについて

C++0x で新しく追加されるユーザ定義リテラルはアンダースコアから始まってないとダメという制約がありますが、これがコンパイル時に問題にならないということは hito さんが書いています(本の虫: user defined literalが予約語の制約を無視できる理由)。 で…

move semantics に関するメモ(2)

混乱の原因は std::forward()。 std::forward() の実装はいまのところこんな感じになっているらしい。 template <class T, class U, class = typename enable_if< (is_lvalue_reference<T>::value ? is_lvalue_reference<U>::value : true) && is_convertible<typename remove_reference<U>::type*, typename remove_reference<T>::type*>::value >::type> i…</t></typename></u></class>

move semantics に関するメモ

多分間違いもあるので鵜呑み厳禁。 →大量に間違いがあるのでこのエントリは無かったことにしましょう。 左辺値 struct X { }; X x; // x は左辺値 左辺値参照型の左辺値 struct X { } x; X& rx = x; // rx は左辺値参照型の左辺値 左辺値参照型の右辺値 stru…

N2844 - Fixing a Safety Problem with Rvalue References の翻訳

翻訳してみました。 http://melpon.tank.jp/pukiwiki147/index.php?Memo%2F%CB%DD%CC%F5%2FN2844%20-%20Fixing%20a%20Safety%20Problem%20with%20Rvalue%20References 要約っぽいの 右辺値参照は「型安全オーバーロードの原則」に反しているという話。 templ…

TMP で Maybe モナド

namespace monad { namespace maybe { struct nothing { }; template<class A> struct just { }; template<class A> struct ret { typedef just<A> type; }; template<class M, template<class> class F> struct bind; template<class A, template<class> class F> struct bind<just<A>, F> { typedef typename F<A>::type …</a></just<a></class></class></a></class></class>

inits, scan

メタプロは続くよどこまでも。 // inits // リストのすべての先頭部分リストを長さの増加する順に並べたリストを返す // [α]→[[α]] namespace inits_detail { template<class L1> struct concat_bind { template<class L2> struct f { typedef typename binary_concat<L1, L2>::type type</l1,></class></class>…

zip

こんなのを思いついた。 template<class Pair> struct zip; template<class... S1, class... S2> struct zip<pair<tuple<S1...>, tuple<S2...>>> { typedef tuple<pair<S1, S2>...> type; }; ……けど S1 と S2 の長さが違うとアウトでしたorz なので take を実装して長さを短いほうに合わせてからやってやるといけそうな感じ。 追記: でけ</pair<s1,></s2...></pair<tuple<s1...></class...></class>…

関数プログラミング楽しい

最近アキラさん(id:faith_and_brave)からいろいろ本を借りて読んでるのですが、その中でも関数プログラミング作者: R.バード,P.ワドラー,武市正人出版社/メーカー: 近代科学社発売日: 1991/04/01メディア: 単行本購入: 7人 クリック: 82回この商品を含むブ…

N2800 - 20.8 Time utilities の翻訳

chrono について調べる必要が出てきたので、理解を深めるために該当箇所を翻訳してみました。 http://melt.sytes.net/pukiwiki147/index.php?Memo%2F%CB%DD%CC%F5%2FN2800%20-%2020.8%20Time%20utilities%28JP%29 duration クラス duration クラスは C# で言…

scope_guard

ScopeGuard - Faith and Brave - C++で遊ぼう を見て、面白そうなので C++0x で書いたらどうなるかなーと思ってやってみた。 class scope_guard_impl_base { protected: scope_guard_impl_base() : dismissed_(false) { } scope_guard_impl_base(const scope…

N2709 - 非同期実行のための Packaging Tasks

http://melpon.tank.jp/pukiwiki147/index.php?Memo%2F%CB%DD%CC%F5%2FN2709%20-%20Packaging%20Tasks%20for%20Asynchronous%20Execution スレッドから値を返してもらうためのクラス。 全く同じ事が promise を使ってやることが出来るけど、このクラスを使え…

N2671 - 非同期 Future Value

そういえば大分前に翻訳して貼ってなかったので。http://melpon.tank.jp/pukiwiki147/index.php?Memo%2F%CB%DD%CC%F5%2FN2671%20-%20An%20Asynchronous%20Future%20Value%A1%A7%20Proposed%20Wording 概念的には、マルチスレッドデザインパターンの Future …

nested_exception のサンプル

例えば自前の XML 読み込みクラスみたいな複雑な作る場合なんかはいろんな(out of range とか null reference、他にも exception を継承していない例外とか、他社ベンダのライブラリを使うならそれが提供している例外とか)例外が出る可能性があるので、そ…

nested_exception

id:faith_and_brave:20081203 の InnerException を、nested_exception で書いてみた。 class my_nested : public exception { private: const char* what_; public: my_nested(const char* what) : what_(what) { } virtual const char* what() const throw…

N2748 - Strong Compare and Exchange

http://melpon.tank.jp/pukiwiki147/index.php?Memo%2F%CB%DD%CC%F5%2FN2748%20-%20Strong%20Compare%20and%20Exchange compare-and-exchange は、実装によっては以前の値と同じ場合でも失敗することがあるのだけれども、それが起こる weak バージョン(今ま…

N2668 - Concurrency Modifications to Basic String

http://melpon.tank.jp/pukiwiki147/index.php?cmd=read&page=Memo%2F%CB%DD%CC%F5%2FN2668%20-%20Concurrency%20Modifications%20to%20Basic%20String basic_string の copy-on-write 実装(書き込み時に文字列をコピーする実装)を実質上禁止するというも…