boost multi_index_container と composite_key を使用して、次のようなことを実現したいと考えています。
struct LogicalAnd {
bool operator()(const int& argVal1, const int& argVal2) const {
return int(argVal1 & argVal2) == argVal1;
}
};
template<class T, class Enable = void>
class FooContainer;
template <class T>
struct FooContainer<T,typename boost::enable_if<boost::is_base_of<IFoo, T> >::type> {
typedef multi_index_container<
boost::shared_ptr<T>,
indexed_by<
hashed_non_unique<
composite_key<
T,
const_mem_fun<T,int,&T::getKey1>,
const_mem_fun<T,int,&T::getKey2>
>,
composite_key_equal_to<
LogicalAnd,
LogicalAnd
>
>
>
> shared_ptr_type;
};
知っています:
namespace CustomKey {
typedef enum {
VAL1 = 0x00000001,
VAL2 = 0x00000002,
ALL = 0xFFFFFFFF
} type;
}
目標は、次のことを実行できるようにすることです。
container.find(boost::make_tuple(CustomKey::VAL1, CustomKey::ALL));
これにより、LogicalAnd が true を返すすべての要素を取得できます。
問題は、LogicalAnd コンパレータを multi_index_container で動作させることができないことです。
composite_key_equal_to の直前に composite_key_hash を追加することでビルドできます。
composite_key_hash<
boost::hash<int>,
boost::hash<int>
>
でもfind操作が思うように動かないのであまり変わらず…
ブーストのドキュメントを検索したり、さまざまな実装を試したりしましたが、情報量に溺れています...
どんな助けでも大歓迎です!