C++

-Wc++compat

gcc にこんなオプションあるの知らなかった。試しに付けて↓をコンパイルしてみると、 #include <stdlib.h> typedef struct hoge { int a; int b; } hoge_t; int main(void) { hoge_t *p = 0; p = malloc(sizeof * p); free(p); return 0; } % gcc -Wall -Wextra -Wc++-</stdlib.h>…

function try block?

C++

ネタ元 Ruby on Rails application could not be started Ruby on Rails application could not be started #include <iostream> #include <stdexcept> #include <boost/lexical_cast.hpp> using namespace std; using namespace boost; #define d(str) (cout << str << " @ " << __func__ << endl) class </boost/lexical_cast.hpp></stdexcept></iostream>…

FizzBuzz

C++

制御構文・論理演算を一切使わずに FizzBuzz - odz buffer おぉ、なるほど。一時オブジェクト作りまくりで書くとこんな感じ? template 勉強しないと。 #include "iostream" #include "sstream" using namespace std; template <bool mod3, bool mod5, int i> struct FizzBuzzString { stri</bool>…

STL 難い

C++

give up. // 本当は status は違うクラスの内部クラス class status { public: void tick() { /* do something */ } };hash_map<int, status> node_status;for_each( node_status.begin(), node_status.end(), compose1( mem_fun(&status::tick), select2nd< hash_map<int, status>::va</int,></int,>…

log を読む処理で boost::spirit を持ち出そうとして躊躇

C++

とある log をパースする処理を書かないといけないんだけど、ゴリゴリ書くか boost::spirit 使うか迷う。ゴリゴリは書きたくないんだけどなぁ。短く美しく書きたいけど、boost::spirit を持ち出すほどの物でも無い気がするし…。

gcc の STL を STLPort 5.0 に入れ替え

C++

インストール自体は簡単。適当な場所にアーカイブを展開して、 sudo make -f gcc.mak clean install できたら試しに次のコードをコンパイルしてみる。 #ifdef _DEBUG #define _STLP_DEBUG 1 #else #undef _STLP_DEBUG #endif #include <vector> int main(void) { std</vector>…

Boost 1.33.1 with STLPort 5.0

C++

リンクに失敗するから stlport.jam の一番最後の方を弄って適当に対処。 if ! $(STLPORT_AUTOLINK) { STLPORT_LIB_STATIC_SUFFIX ?= "" ; for local v in $(STLPORT_VERSIONS(5)) { flags $(CURR_TOOLSET) FINDLIBS <stlport-version>$(v)/<runtime-build>debug/<runtime-link>static : stlportstl$(STLPORT</runtime-link></runtime-build></stlport-version>…

gcc 3.4.3 + STLport-5.0

C++

gcc 3.4.3 な環境に STLport-5.0 を入れてみた。 通常のコンパイルでは、まぁ、こんな感じ。 g++ -pthread -L/usr/local/STLport/lib -I/usr/local/STLport/stlport/ -lstlport -O hoge.cppDebug モードでは、まぁ、こんな感じかなぁ。 g++ -pthread -L/usr/…