タグ

c++とcontainerに関するmitsu1986のブックマーク (1)

  • ベターsetとしてmulti indexを使う - Faith and Brave - C++で遊ぼう

    コンテナに複数のインデックスを持てるBoost.MultiIndexですが、単一のインデックスだけを持たせるだけでも便利に使えます。ここでは、std::setを置き換えて使ってみます。 std::setにユーザー定義型を格納する場合、キーの比較を自分で定義する必要があります。そしてその比較が一部のメンバ変数だけで完結する場合、std::setでは比較に必要なメンバ変数以外に、ダミーの値を入れたオブジェクトを作る必要があります。 #include <iostream> #include <set> struct X { int a = 0; int b = 0; int c = 0; X(int a, int b, int c) : a(a), b(b), c(c) {} }; struct XLess { bool operator()(const X& x, const X& y) co

    ベターsetとしてmulti indexを使う - Faith and Brave - C++で遊ぼう
  • 1