std :: vector:でうまく機能するこれらの2つの関数について考えてみます。
int connectNode(GraphNode const& newNode,std::vector<GraphNode const*>::const_iterator beginCandidates, std::vector<GraphNode const*>::const_iterator endCandidates){
int connections =0;
for (auto iter= beginCandidates; iter!= endCandidates; ++iter) {
if(connectNodes(newNode,**iter)) ++connections;
}
return connections;
}
int connectNode(GraphNode const& newNode,std::vector<GraphNode>::const_iterator beginCandidates, std::vector<GraphNode>::const_iterator endCandidates){
int connections =0;
for (auto iter= beginCandidates; iter!= endCandidates; ++iter) {
if(connectNodes(newNode,*iter)) ++connections;
}
return connections;
}
これらの関数はベクトルに対してはうまく機能しますが、セットなどのその他のコンテナーに対しては明らかに機能しません。それらをどのように一般化することができますか。私が考えることができる唯一の可能な解決策は、いくつかの非常に醜いenable_if回避策を使用することです。簡単な解決策はありますか?編集:明確にするために:通常のコンテナー用とポインターコンテナー用の両方の関数が必要です。実際のロジックは、2つの参照をとるconnetNodes内で発生します。(最初の関数の**に注意してください)