C++と色々

主にC++やプログラムに関する記事を投稿します。

2014-06-01から1ヶ月間の記事一覧

C++ Testing Framework Catchの紹介

C++

CatchとはC++のテスティングレームワークの1つです。ヘッダオンリーで使うことが出来ます!簡単! https://github.com/philsquared/Catch 私はこちらのブログを拝見して知りました。 ブログズミ: C++ Testing Framework の Catch を使ってみた Google Testな…

選択ソート書いてみた

普通のと、デバッグ用ストリーム出力ありのやつ #include <algorithm> #include <iterator> #include <functional> #include <utility> template <typename Iterator> void selection_sort(Iterator first, Iterator last) { selection_sort(first, last, std::less<>{}); } template <typename Iterator, typename Compare> void selection_sort(…</typename></typename></utility></functional></iterator></algorithm>

バブルソート書いてみた

普通のと、デバッグ表示用の2種類 #include <algorithm> #include <iterator> #include <functional> #include <utility> template <typename Iterator> void bubble_sort(Iterator first, Iterator last) { bubble_sort(first, last, std::less<>{}); } template <typename Iterator, typename Compare> void bubble_sort(Iterator first,…</typename></typename></utility></functional></iterator></algorithm>

型名と変数名

C++ではユーザ定義型と同名の変数を作ることが出来ます。型名か変数名か曖昧な文では変数と解釈されます。型名を表したい時は型名の前にclassもしくはstructをつけます。 class hoge {}; int main() { hoge hoge; // 型名と同じ名前の変数を作って良い hoge;…

テンプレートテンプレートパラメータにtypenameキーワードを使えるようにする

C++

N4051 Allow typename in a template template parameter 今のC++ではテンプレートテンプレートパラメータにはclassキーワードしか使えません。 template <template <typename> class T> // OK struct A; template <template <typename> typename T> // NG struct B; この制限を無くして、typenameキ</template></template>…

C++の関数のオーバーロード解決について

C++

問題です。以下のコードで、(a)、(b)、(c)、どの関数が呼ばれるでしょうか。 #include <iostream> using std::cout; // (a) template <typename T> void f(T) { cout << "f(T)"; } // (b) template <> void f(int*) { cout << "f(int*)"; } // (c) template <typename T> void f(T*) { cout << </typename></typename></iostream>…