2009-01-01から1年間の記事一覧

Boost.勉強会感想とか

遅ればせながらBoost.勉強会の発表資料をアップしました。 http://cid-31a4fb569979bef3.skydrive.live.com/self.aspx/.Public/BoostAsio.ppt ※以下TLにあった質問ぽいものに対して解答 Q:AsioってCOMポート扱えるの? A:はい、発表資料に書いたとおり扱え…

C++でPropertyつづき

C++

前のエントリーに上書きしちゃったみたいです。汗 Boost.Propertyの実装案みたいなもの->http://codepad.org/A4vaAMPZ これみて簡単にならないかやってみました。 #include <boost/typeof/typeof.hpp> #include <iostream> template<typename T> struct property_get_type; template<typename ReturnType,typename Class> struct property_get_type</typename></typename></iostream></boost/typeof/typeof.hpp>

C++でPropertyつづき1

C++

self()呼び出しもできた。http://codepad.org/eKAdqttP 以下に同じコードを #include <boost/typeof/typeof.hpp> #include <iostream> template<typename T> struct property_get_type; template<typename ReturnType,typename Class> struct property_get_type<ReturnType (Class::*)() const> { typedef ReturnType type; }; template</returntype></typename></typename></iostream></boost/typeof/typeof.hpp>

もしもBoost.Threadにinterruptが無かったら。

C++

VC限定なコードですけが、こんな感じで追加できるんじゃないかと。 元ネタはtwitterでid:melponさんがstd::threadにinterruptが無いので欲しいってとこからです。 id:melponさんがつぶやいてたコードの大部分借りました。 #include "stdafx.h" #include <iostream> #pr</iostream>…

もはやBoost.ScopeExit・・・

C++

#include <iostream> #include <boost/typeof/typeof.hpp> #include <boost/preprocessor/seq/cat.hpp> #include <boost/preprocessor/seq/for_each_i.hpp> // Steven Watanabe's trick namespace closure { namespace args { template<int> struct declare; typedef void* declared; struct undeclared { declared dummy[2…</int></boost/preprocessor/seq/for_each_i.hpp></boost/preprocessor/seq/cat.hpp></boost/typeof/typeof.hpp></iostream>

boost::filesystemを使ってある拡張子のファイルの先頭行に文字列を

C++

ちょっと必要になったので書いてみただけです。>< #include <iostream> #include <string> #include <boost/filesystem.hpp> #include <boost/filesystem/fstream.hpp> #include <boost/xpressive/xpressive.hpp> void replace_file( const boost::filesystem::path& dir, const std::string& inset_str) { try { namespace fs = boost::filesyste…</boost/xpressive/xpressive.hpp></boost/filesystem/fstream.hpp></boost/filesystem.hpp></string></iostream>

ちょっとだけクロージャを作ってみるのメモ

C++

#include <iostream> #include <vector> #define CLOSURE_(A0) CLOSURE_DEF(##A0, __LINE__) #define CLOSURE_DEF(A0, id) CLOSURE_IMPL(A0, id) #define CLOSURE_IMPL(A0, id)\ struct Closure_##id {\ typedef decltype(A0) Arg0;\ Arg0& A0;\ Closure_##id(Arg0& a0) : A0(a</vector></iostream>…

N2855 noexceptについて

C++

C++0xの新しい提案でN2855(Rvalue References and Exception Safety)では、noexceptというキーワードが追加されています。 まずはコードから見ます。 noexcept int foo(int); int bar(int); noexcept void wibble(int x, int y) { x = foo(x); // OK: foo()…

練習でstd::reference_wrapperがラップしてる型を取得するメタ関数を作ってみた

C++

std::reference_wrapperの場合は保持してるTを返します。 std::reference_wrapperではない場合は受けた型をそのまま返します。 #include <functional> #include <tuple> namespace mpl { template<class T> struct remove_wrap; { typedef T type; }; template<class T> struct remove_wrap<std::reference_wrapper<T>> { typ</std::reference_wrapper<t></class></class></tuple></functional>…

ユーザ定義リテラルまとめ

C++

このエントリは見事に間違ってたので忘れてください。>< グローバルな名前空間でもユーザ定義リテラルは定義できます。参考 http://cpplover.blogspot.com/2009/09/user-defined-literal.htmlところで新たな疑問があったのでここにメモ。 template <char... C> std::s</char...>…

C++テンプレートテクニック

C++

やっとレビューを書きます。id:faith_and_braveさんとεπιστημηさんの共著 C++テンプレートテクニック この本はタイトルの通りC++のテンプレートを使ったテクニック集になってます。 対象の読者は中級以上といったところでしょうか。 STLを使ってプログラミン…

mpl勉強モード

C++

enable_ifを使ってテンプレートメンバー関数を特殊化してみた? #include <iostream> #include <string> #include <typeinfo> #if defined(__GNUC__) #include <type_traits> #include <cxxabi.h> #endif #if !defined(__GNUC__) template <bool b, class T> struct enable_if; template <class T> struct enable_if<true, T> { typedef T type; }; #…</true,></class></bool></cxxabi.h></type_traits></typeinfo></string></iostream>

Scalaメモ

http://itpro.nikkeibp.co.jp/article/COLUMN/20080613/308019/ ここ全部読む。

Windows版gcc4.4でC++0xのコードをコンパイルに`c++0x'だけではダメ

C++

コンパイルオプションに`-std=c++0x'だけではダメで、`gnu++0x'も指定する必要があります。 (もしくは`gnu++0x'だけでも良いかもしれません。) 結論としては`-std=c++0x'ではなく、`-std=gnu++0x'を指定しなければいけません。 C++0xのコードをコンパイルす…

クラスのポインタをvoid*でdeleteした場合デストラクタが呼ばれない

C++

意外と知らない人が多かったので簡単なサンプル #include <iostream> struct Hoge { ~Hoge() { std::cout << __FUNCTION__ << std::endl; } }; int main() { Hoge* p = new Hoge; void* pv = p; delete pv; return 0; } 実行結果 gcc4.4 実行結果 VC8 必ず正しいクラス</iostream>…

Erase-Remove Ideomを少しでも楽に使うために。(自分用メモ)

C++

こんな感じでコンテナの値を削除できるようにしてみた。 #include <algorithm> #include <vector> struct Hoge { int num_; explicit Hoge(int i) : num_(i) {} int getnum() { return num_; } }; int main(int argc, char** argv) { std::vector<Hoge> v; v.push_back(Hoge(1)); v.pu</hoge></vector></algorithm>…

boost::threadとstd::thread周りを調べてたら

C++

こんな記事を見つけました。 http://msdn.microsoft.com/ja-jp/magazine/cc163405.aspx 以下記事内に書かれているWindows Vista以降で使用可能な関数とPosixとの対応表を作ってみました。 PosixAfter Windows Vista pthread_cond_initInitializeConditionVar…

__FUNCTION__マクロのwchar_t版

C++

VCでは char版は__FUNCTION__ wchar_t版は__FUNCTIONW__ ほかには__FILE__も__FILEW__が存在します。 xutilityヘッダに以下のように定義されてます。 #define __STR2WSTR(str) L##str #define _STR2WSTR(str) __STR2WSTR(str) #define __FILEW__ _STR2WSTR(_…

月曜日から

徹夜です。 3日おきにリリースとかアジャイルにもほどがあります。 今までガチガチのウォーターフォールでやってきたくせに! ばか! そいえば昨日The翻訳2009プレミアム専門辞書パック買いました。 おかげで今月と来月は金欠状態です。 本当にありがとうご…

N2800 P29の一部を訳してみました。

C++

原文§ 2.13.7の2 2 A user-defined-literal is treated as a call to a literal operator or literal operator template (13.5.8). To determine the form of this call for a given user-defined-literal L with ud-suffix X, the literal-operator-id whos…

まだ考えてました。

C++

#include <tuple> #include <iostream> #include <string> #include <functional> #include <stdexcept> void printf(const char *s) { while (*s) { if (*s == '%' && *(++s) != '%') throw std::runtime_error("invalid format string: missing arguments"); std::cout << *s++; } } template</stdexcept></functional></string></iostream></tuple>

こんなのしか思いつかなかった。

C++

可変引数を保持しておいてそれを別な関数に渡すには? やりたい事と違うかもしれませんが #include <tuple> #include <iostream> #include <string> template <class T> void do_something(const T& t) { std::cout << t << std::endl; } template <class Tuple, size_t N> struct do_tuple_helper { static void do_al</class></class></string></iostream></tuple>…

いまさらですが。

mplを勉強中。C++関連の勉強会があれば今度わんくまの勉強会に参加してみたいなー。

threadクラスの実装を晒す2

C++

日にちがあいてしまいましたがエラー処置と引数を追加していきます。 コンストラクタで行っていた処理をstart_thread関数に移しています。 それに伴いthread_base*をメンバー変数p_にしました。 // thread.hpp #include <memory> // std::auto_ptr #include <process.h> // ::_b</process.h></memory>…

前回雑記で書いたthreadクラスの実装を晒す

C++

実装を見る前にもう一度threadクラスの使い方を見ておきます。 #include <iostream> #include "thread.hpp" // これから実装を見ていくthreadクラスのヘッダファイル void foo() { std::cout << "fooを実行しています" << std::endl; } int main() { thread t(foo); //</iostream>…

やっとリンク集を作成

といってもまだ全然追加してません。 仕事で徹夜続きで頭がまわらない。ところで、C++0xのthreadクラスがWindows上で使える環境が手元に無いので作ってしまいました。 前回refが必要になったのはこのthreadクラスのコンストラクタに渡す引数を テンプレート…

boostのrefが必要になったので作ってみた

C++

boostにあるref相当の物が必要になりました。 なので作ってしまいます。 template class reference_holder { T& val_; public: reference_holder(T& arg) : val_(arg) {} // Tのリファレンスを保持 operator T&() { return val_; } // 型変換を利用してTのリ…

ISO/IEC 14882:2003 PDFをみつけた。

C++

これってまずいんじゃないですか?(^-^; それとも偽者? http://code.google.com/p/openassist/downloads/detail?name=C%2B%2B%20Standard%20-%20ANSI%20ISO%20IEC%2014882%202003.pdf&can=2&q=

オーナードローって何ですか?おいしいんですか?

さて、MFCのCButtonBitmapの実装をヒントにCButtonのオーナードローをさくせいちゅう。 ボタンの上にマウスあわせると貼り付けたビットマップが変わるようなやつ。 これめんどくさいわー。MSDN見ても実際試してみないとわかんなかったし。 GetSafeHandle()っ…

gcc4.4のthreadがコンパイルできない

C++

Windows版だけかもしれませんが、C++0xのヘッダは以下の定義が入っていてclass threadが使えなかったです。 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) これらはで定義されてます。 /* Define if gthreads library is ava…