2016-10-23 5 views
0

Boost multiindexコンテナのドキュメントは、反復処理を行うインデックスを宣言した後にセットとして使用できることを示しているようです。ヘッダー反復子を返して、multiintexコンテナをstd :: set <> :: iteratorとして戻します。

typedef multi_index_container< 
    Employee, 
    indexed_by< 
     ordered_non_unique< 
      composite_key< 
       Employee, 
       member<Employee, int, &Employee::id>, 
       member<Employee, int, &Employee::salary> 
      > 
     > 
    > > EmployeeSet; 
const std::set<Employee>::iterator getEmployees(); 

static EmployeeSet employeeSet; 

Test.cc:

const std::set<Test::Employee>::iterator getEmployees(){ 
    std::pair<EmployeeSet::iterator, EmployeeSet::iterator> by_id = 
    employeeSet.equal_range(id); 
    return by_id.first; 
} 

です、それは例std::set

にイテレータとしてマスカレードブースト実装を隠し、イテレータを返すことが可能となるのであれば、私は思っていましたこのようなことをすることは可能でしょうか?そしてどうやって?

答えて

2

いいえ、できません。あなたが定義したEmployeeSetは、std::set(実際にはstd::multiset)のように機能しますが、それは1つではありません。これらの無関係なコンテナの種類は異なります。したがって、あなたは他のコンテナを渡すことはできません。

なぜiteratormulti_index_containerのインデックスにstd::set::iteratorとして渡す必要があるか再考することができます。

関連する問題