K
Konstantin
I have two possible implementations of my class:
template <typename T>
class MyContainer
{
public:
typedef typename std::set<T>::const_iterator const_iterator;
void add( T id ) { data.insert(id); }
void remove( T id ) { data.erase(id); }
private:
std::set<T> data;
};
template <typename T>
class MyContainer
{
public:
typedef typename std::list<T>::const_iterator const_iterator;
void add( T id ) { data.push_back(id); }
void remove( T id ) { data.remove(id); }
private:
std::list<T> data;
};
which suggests that another parameter in the template could be added.
How to specialize the template correctly so that I could, for example, switch the underlying container:
typedef MyContainer<InstanceID, set>::const_iterator mycontainer_iterator;
MyContainer<InstanceID, set> mycontainer;
or
typedef MyContainer<InstanceID, list>::const_iterator mycontainer_iterator;
MyContainer<InstanceID, list> mycontainer;
template <typename T>
class MyContainer
{
public:
typedef typename std::set<T>::const_iterator const_iterator;
void add( T id ) { data.insert(id); }
void remove( T id ) { data.erase(id); }
private:
std::set<T> data;
};
template <typename T>
class MyContainer
{
public:
typedef typename std::list<T>::const_iterator const_iterator;
void add( T id ) { data.push_back(id); }
void remove( T id ) { data.remove(id); }
private:
std::list<T> data;
};
which suggests that another parameter in the template could be added.
How to specialize the template correctly so that I could, for example, switch the underlying container:
typedef MyContainer<InstanceID, set>::const_iterator mycontainer_iterator;
MyContainer<InstanceID, set> mycontainer;
or
typedef MyContainer<InstanceID, list>::const_iterator mycontainer_iterator;
MyContainer<InstanceID, list> mycontainer;