独自のコンテナを実装しました:
template<typename T>
class MyContainer
{
// body where in some point 2 elements of collection are compared (-1, 0 and 1 possible comparison results)
};
私がやりたいのは、std::set のように、関数オブジェクトのサポートを追加することです。ここでは、次のような関数オブジェクトを実行できます。
struct Comparator
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
そしてそれを設定パラメータとして渡します:
std::set<const char*, Comparator> SomeSet;
私は毎日の C++ プログラマーではないので、それを達成するには助けが必要です。これにサポートを追加するには、どうすればよいですか? MyContainer
関数オブジェクトを格納してコンテナー内のソート メソッドで使用するには、フィールドを作成する必要がありますか?