メモの日々


2013年01月07日(月) [長年日記]

  • 今日が仕事始め。

[c++] 連想コンテナの比較ファンクタをboost::bindで与える

std::setの比較ファンクタをboost::bindを使ってその場で与えたかった。が、STLの連想コンテナは比較ファンクタの型を指定する必要があるのでアルゴリズムを使うときのようにはいかない。

比較ファンクタの型をboost::functionを使って定義すればできたのでメモ。

#include <iostream>
#include <set>
#include <boost/bind.hpp>
#include <boost/function.hpp>

struct A {
    int i;

    A(int i) : i(i) {}
};

int main() {
    typedef std::set<A*, boost::function<bool(const A*, const A*)> > ASet;
    ASet s(boost::bind(&A::i, _1) < boost::bind(&A::i, _2));

    A a1(1);
    A a2(2);
    A a3(3);

    s.insert(&a3);
    s.insert(&a1);
    s.insert(&a2);
    s.insert(&a1);

    for (ASet::iterator it = s.begin(); it != s.end(); ++it) {
        std::cout << (*it)->i << std::endl;
    }
}
1
2
3

2013年01月16日(水) [長年日記]

[dev][howto] git-svnで空ディレクトリを削除

gitリポジトリ上でディレクトリを削除しても、git svn dcommit した先のsubversionリポジトリではディレクトリが削除されなかった。

% git svn dcommit --rmdir

と--rmdirオプションを付ければ削除されるみたい。git-svn(1) Manual Pageから引用。

--rmdir

Only used with the dcommit, set-tree and commit-diff commands.

Remove directories from the SVN tree if there are no files left behind. SVN can version empty directories, and they are not removed by default if there are no files left in them. git cannot version empty directories. Enabling this flag will make the commit to SVN act like git.

config key: svn.rmdir