C++

sphinx + breatheでAttributeError: 'NoneType' object has no attribute 'replace'

以下のようなエラーがSphinx + Breatheで出る。 # Sphinx version: 1.6.3 # Python version: 3.6.2rc1 (CPython) # Docutils version: 0.13.1 release # Jinja2 version: 2.9.6 # Last messages: # building [mo]: targets for 0 po files that are out of d…

std::stringでtolower/toupper

C++

#include <algorithm> #include <string> std::string data = "Abc"; std::transform(data.begin(), data.end(), data.begin(), ::tolower); std::transform(data.begin(), data.end(), data.begin(), ::toupper); Reference c++ - How to convert std::string to lower case? -</string></algorithm>…

Travis CIでビルドの回数を抑える時

C++の場合は、一回のビルド・テストに非常に時間がかかるので、ビルドを減らしたい場合がある。 Travis CIでは、設定で Build pushs push時にビルド Build pull requests pull request 時にビルド がある。 両方ONにすると、PR時に2回ビルドが走ることになる…

boostでdemangleする

C++

boost/coreにはいくつかのutility系の機能がある。 boost/core/demangle.hppはdemangleを提供する。 使い方 #include <boost/core/demangle.hpp> #include <typeinfo> #include <iostream> template<class T> struct X { }; int main() { char const * name = typeid( X<int> ).name(); std::cout << name << std::endl; </int></class></iostream></typeinfo></boost/core/demangle.hpp>…

Aligntaでvimで行末のコメントを揃える

vimで行末のコメントを揃えるときの話。 矩型選択などを利用して揃えるものはあるが、プラグインを使った解説をしているものがなかったのでメモ。 準備 Aligntaを入れる。 Alingtaは、文章整形用のvim plugin。 同様のツールにAlignがあるが、Aligntaの方が…

ublasのouter_prodの計算式

C++

boostのublasにはouter_prodというベクトルとベクトルの転置の積を計算する関数が存在する。 どちらのベクトルが転置されているかちゃんと書いたものがなかったのでメモ。 直積の演算としては直感通りの式。 $$ x = \left( \begin{array}{c} x_{1} \\ x_{2} …

C++で配列の型のtypedef

C++

配列のtypedefをするときは次のようにする。 //int[2]のtypedef typedef int type[2];

boost::numeric::ublas::vectorの速度比較

C++

boost/numeric/ublas/vectorの生成と代入に関する速度をまとめた。 要素数を5千万にして生成と代入の速度を計測。 compiler及び環境 i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00) Macbookair 20…

C++のclassとstructの違い

C++

はっきりとした言及があまりなかったので一応メモ。 Cにおいてclassとstructは(Cには記憶クラスというものがあって)全くの別物だが、C++ではstructとclassに機能的な違いはない。 structとclassの違い 振る舞いとしての唯一の違いはデフォルトのアクセス指…

C++のstaticに関するまとめ

C++

static(メンバ)変数への代入について知識がうろ覚えだったので、整理した。要点は以下。 staticな変数は宣言と同時に代入する staticなstruct型の初期化は{}で行う. class内のstaticなメンバに代入するときはクラスの宣言の外で代入.また型の指定が必要. c…

C++の組み込み型はクラスとして扱える

C++

タイトル通り。 doubleという名前のクラスと思って以下でdoubleの値を生成できる。 double a = double() double b = double(1.0) ポインタも同様のことが可能だがtypedefが必要 double* a = double*(); //error double* b = (double*)(); //error typedef do…

boost::bindとboost::functionをメンバ関数に使う

C++

タイトル通り。 boost::bindはメンバ関数を指定すると、第一引数にクラスを引数に取る関数として解釈される。 例 #include <iostream> #include <boost/function.hpp> #include <boost/bind.hpp> struct LinearExtrapolation { LinearExtrapolation( const double leftPoint, const double leftValue, const</boost/bind.hpp></boost/function.hpp></iostream>…

C++でClass内のtypedefにもpublic, privateは適用される

C++

タイトル通りだが、以下がサンプル。 テンプレートを使う時に重要になるのでメモ。 class Test { private: typedef double private_real; public: typedef double public_real; }; int main(int argc, char const* argv[]) { Test::public_real public_real …

Macportsでcppunitのインストール

Macportsでcppunitをインストールする。幸いなことに、最新版がインストールできそう。 sudo port install cppunit でOK。 サンプルを実行 正しくインストールされているかサンプルを実行する。 サンプルはcppunitのソースファイルのexampleを利用するので、…