私は次のクラスを持っています:
#include <set>
#include <stack>
#include <queue>
#include <string>
template <typename T>
class MySet
{
public:
const std::stack<T> data() const
{
std::stack<T> other_cont ( typename std::stack<T>::container_type ( cont.begin(), cont.end() ) );
return other_cont;
}
private:
std::set<T> cont;
};
そして、次のコード:
MySet<std::string> a;
MySet<int> b;
const std::stack<std::string> s = a.data();
const std::queue<int> q = b.data();
1 つのテンプレート化されたメンバー関数を使用して、アダプターの型を初期化したいと考えています。これまでのところ、またはのいずれかでのみ機能しますstack。queueテンプレートを使用して一般化する方法がわかりません。
これは私が試したことです:
template <template <typename> typename M>
const M<T> data() const
{
M<T> other_cont ( typename M<T>::container_type ( cont.begin(), cont.end() ) );
return other_cont;
}
コンパイラは、テンプレート パラメータを推測できないと言っていますM。