C++

ClangCheck をつかってみた

Clang の clang-tools-extra に含まれている ClangCheck を使ってみました。 ClangCheck は Clang の LibTooling を使用したシンタックスチェッカーです。 LibTooling - Clang 3.3 documentation ClangCheck - Clang 3.3 documentation [main.cpp] void func…

Clang に Inheriting constructors と Thread-local storage が実装された

C++

ClangがC++11を完全実装! 繰り返す、C++11を完全実装 - 本の虫 C++98, C++11, and C++14 Support in Clang - Clang と、いうことらしいので早速コンパイルして試してみました。 [ソース] struct foo{ constexpr foo(int x, int y, int z) : x(x) , y(y) , z…

cpp11-migrator を試してみた

[追記] さっき気づいたんですが cpp11-migrate を行うとインクルードしているヘッダーファイル内も全て C++11 で書き換えられてしまうようです。 なのでインクルードしている標準ライブラリも書き換えられてしまうので注意して下さい。 回避方法はあるのかな…

C++ で物理アドレスの取得

C++

winsock2 を使用した版。 [ソース] #include <winsock2.h> #include <iphlpapi.h> #include <vector> #include <iostream> #include <iterator> #include <iomanip> #include <boost/format.hpp> #pragma comment(lib,"iphlpapi.lib") typedef std::vector<unsigned char> mac_address; std::vector<mac_address> get_mac_addresses()…</mac_address></unsigned></boost/format.hpp></iomanip></iterator></iostream></vector></iphlpapi.h></winsock2.h>

Sprout で乱数の配列を生成する

Sprout で乱数の配列を生成する場合、sprout::generate と sprout::random::combine を使用します。 [ソース] #include <sprout/random.hpp> #include <sprout/array.hpp> #include <sprout/algorithm.hpp> #include <iostream> int main(){ static constexpr sprout::default_random_engine engine; static constexpr sprout::unif</iostream></sprout/algorithm.hpp></sprout/array.hpp></sprout/random.hpp>…

Sprout.Random で次の乱数を取得する

constexpr 時の Sprout.Random は内部の値が変更できない為、標準ライブラリ とは違い operator() を何回呼び出しても同じ値しか返ってきません。 ではどうやって次の乱数値を取得するのかというと operator() を再度呼び出します。 [ソース] #include <sprout/random.hpp> #inc</sprout/random.hpp>…

Sprout.Random でコンパイル時に暗号化の鍵を生成

やってみました。 [ソース] #include <algorithm> struct ango{ explicit ango(int key) : key(key){} template<typename Range> Range operator ()(Range range) const{ typedef typename std::iterator_traits<decltype(std::begin(range))>::value_type value_type; auto result = std::move(range); std::transfor</decltype(std::begin(range))></typename></algorithm>…

Sprout.Random で乱数の種を設定

Sprout.Random で乱数の種を設定する場合、乱数エンジンのコンストラクタに整数値で種を渡します。 また、SPROUT_UNIQUE_SEED マクロを使用する事でコンパイル毎に違う値の種を設定する事が出来ます。 [ソース] #include <sprout/random.hpp> #include <iostream> #include <boost/mpl/print.hpp> int main(){ s</boost/mpl/print.hpp></iostream></sprout/random.hpp>…

ICU を MinGW でビルドする

Qt 5 をビルドする時に必要だったので覚書。 [必要なツール] MinGW msys [ビルド] 基本的にはここに書いてある手順で問題ないです。 [注意] clang のパスが通っていると gcc ではなくて clang の方が使用されるみたいです。 gcc を使用して欲しい場合は clan…

Sprout.Random でコンパイル時乱数

少し使ってみました。 [ソース] #include <sprout/random.hpp> #include <iostream> int main(){ namespace random = sprout::random; static constexpr random::hellekalek1995 engine{}; // 100 ~ 999 static constexpr random::uniform_int_distribution<int> dist1(100, 999); static_asser</int></iostream></sprout/random.hpp>…

本日20:00〜から C++オンライン読書会を行います

C++

C++オンライン読書会を行います。 今日読む資料は『atomic Weapons: The C++ Memory Model and Modern Hardware』になります。 かなり専門的な資料っぽいけど無事に完走出来るだろうか…。 気になる方や参加されたい方は 20時頃に lingr-cpp 部屋までお越しく…

Qt 5.0.1 + MinGW で make した場合に .o ファイルが見つからないとエラーになる

Qt 5.0.1 + MinGW でエラーになった話 その1。 Qt5.0.1 + MinGW を使用して make した時に g++: error: release/main.o: No such file or directory というように .o ファイルが見つからないとエラーになることがあります。 これは makefile 内で .o の出力…

Vim を起動したときに Bjarne Stroustrup に会いたい!

C++

C++er たるもの、日々の感謝の気持ちを込めて C++ の生みの親である Bjarne 氏を毎日拝める必要があります。 プログラマーが毎日見るものといえばエディタですね。 エディタといえば 4月に入っても Advent Calendar 2012 が続いている Vim というエディタが…

C++ でてけとーな暗号化/復号化

C++

排他的論理和を使用したてきとーな暗号化。 [ソース] #include <algorithm> struct ango{ explicit ango(int key) : key(key){} template<typename Range> Range operator ()(Range range) const{ typedef typename std::iterator_traits<decltype(std::begin(range))>::value_type value_type; auto result = std::mo</decltype(std::begin(range))></typename></algorithm>…

Inheriting constructor を使って Variadic Templates 対応版 Boost.Fusion vector

そういえば、Inheriting constructor 実装されたし簡単になりそうだよなーってことで書いてみた。 [ソース] #include <boost/fusion/include/make_vector.hpp> #include <boost/fusion/include/io.hpp> #include <boost/fusion/include/at_c.hpp> #include <iostream> template<typename base> struct inheriting_constructor : base { using base::base; }; temp…</typename></iostream></boost/fusion/include/at_c.hpp></boost/fusion/include/io.hpp></boost/fusion/include/make_vector.hpp>

名前空間で user-defined literals を定義する

C++

名前空間で user-defined literals を定義した場合、そのリテラルを使用する時は using、もしくは using namespace をしておく必要があります。 [ソース] #include <string> #include <iostream> namespace hoge{ std::string operator "" _s(char const* c_str, std::size_t l</iostream></string>…

explicit でキャスト演算子の暗黙の型変換を抑制する

C++

C++ ではキャスト演算子(operator T)を使用することで型から型へ暗黙の型変換を行うことが出来ます。 struct X{ constexpr operator int() const{ return value; } int value; }; constexpr X x{42}; static_assert(x == 42, ""); constexpr int n = x; こ…

正規表現を user-defined literals

C++

正規表現がリテラルで定義出来れば便利だろうか。 [ソース] #include <boost/regex.hpp> #include <string> boost::regex operator "" _r(char const* c_str, std::size_t len){ return boost::regex(c_str); } int main(){ std::string str = "12-34-56"; boost::smatch what; boost:</string></boost/regex.hpp>…

正規表現を raw string literals で定義

C++

Boost.Regex 等で特殊表現を定義する場合に \ を使用するんですが、エスケープシーケンスを回避する為に \\ と既述する必要があります。 boost::regex r("^\\s*\\d+\\-\\d+\\s*$"); assert( boost::regex_match("12-34", r)); assert( boost::regex_match(" …

Visual Studio 2010 の std::wstring::length が正しい値を返さなかった

C++

激しくはまってしまったので覚書。 さて、std::wstring::length は本来であれば文字列の文字数を返します。 std::wstring(L"mado").length(); // => 4 std::wstring(L"ほむ").length(); // => 2 gcc と clang は問題なく文字数を返して来ました。 しかし、な…

PStade.Oven hetero

昨日の記事のコメントで教えて頂いたので覚書。 PStade.Oven に tuple から任意の型の range へと変換する関数が用意されているらしいので使ってみた。 [ソース] #include <pstade/oven/hetero.hpp> #include <boost/tuple/tuple.hpp> #include <boost/any.hpp> #include <iostream> #include <string> struct shape{ virtual void draw() = 0;</string></iostream></boost/any.hpp></boost/tuple/tuple.hpp></pstade/oven/hetero.hpp>…

Boost.Fusion のシーケンスに動的にアクセスする

さて、Boost.Fusion のシーケンスの要素にアクセスする場合、次のようにコンパイル時定数を用いてアクセスする必要があります。 auto v = f::make_vector(42, std::string("homu"), 3.14f, std::string("mado")); constexpr int index0 = 0; int n = f::get<index0>(</index0>…

Uniform Initialization と std::initializer_list

C++

前回の C++読書会で読んだ C++11: A cheat sheet―Alex Sinyakov に書かれていたので覚書。 さて、C++11 で追加された Uniform Initialization なのですが、次のように auto を使用した場合、{} と () では定義される型が変わってしまいます。 // C++11: A ch…

第11回 C++オンライン読書会を行いました。

C++

お陰様でほそぼそとですが、なんとか続けています。 5月に開催される C++Now 2013 まで続けれるといいですね。 第11回 C++オンライン読書会 - boostjp [次回] 日時:04/06(土) 20:00〜 資料:atomic Weapons The C++ Memory Model and Modern Hardware

今夜 20時から C++オンライン読書会を行います

C++

今夜 3/2(土) 20時から C++オンライン読書会を行います。 今日読む資料は『C++11: A cheat sheet―Alex Sinyakov』です。 C++03 と C++11 のコードを比較している非常にわかりやすいチートシートとなっています。 C++11 がよく分かっていない方や C++11 に関…

たった 20 行のコードでひたすらアイドル水着画像をあつめる(C++ + cpp-netlib だよ)

これの cpp-netlib 版です。 cpp-netlib: The C++ Network Library 最新版だとヘッダーオンリーで使えないっぽいのでライブラリをビルドしてリンクする必要があります。 [ソース] #include <boost/network.hpp> #include <boost/xpressive/xpressive.hpp> #include <iostream> int main(){ namespace http = boost::networ</iostream></boost/xpressive/xpressive.hpp></boost/network.hpp>…

たった 37 行のコードでひたすらアイドル水着画像をあつめる(C++ + Boost.Asio だよ)

たった10行のコードでひたすらアイドル水着画像をあつめる - UT Startup Gym たった 4 行のコードでひたすらアイドル水着画像をあつめる(Python だよ) - maeharinの日記 たった3行のコードでひたすらアイドル水着画像をあつめる(Rubyだよ) - Memo いまさら…

clang に Generalized attributes が実装されていた

気がついたら clang の SVN に Generalized attributes が実装されたみたい。 C++98 and C++11 Support in Clang Generalized attributes Alignment support あと Alignment support も何か更新されたのかな。 Inheriting constructors はよ。

httpstatus コマンドで(ry

元ネタ httpstatus コマンドで、HTTP のステータスコードをすばやくしらべる! - tokuhirom's blog. httpstatus コマンドで、HTTP のステータスコードをすばやくしらべる! - Big Sky httpstatus コマンドで、HTTP のステータスコードをすばやくしらべる! - ゆ…

User-defined literals で固定長の Boost.Multiprecision を生成の続き

昨日の続き。 昨日とは違い、その数値が収まる 2のn乗のビット幅を使用するようにしてみました。 [ソース] #include <boost/multiprecision/cpp_int.hpp> template<char ...cs> struct chars{}; constexpr bool operator <=(chars<>, chars<>){ return true; } template<char ...cs> constexpr bool operator <=(chars<></char></char></boost/multiprecision/cpp_int.hpp>…