I have been pondering how one would do such a thing.
For example, the std::set type uses a red-black tree impl.
If I decided that I needed a special impl for set for some
reason, how would one do this ??
So we might have :
// Some function that should be applicable to any impl of set
void doSomething( ?1? theSet)
{
?1?::iterator iter = theSet.begin() ;
// ...
}
std::set<int> s1 ; // the standard STL impl
?2? s2 ; // the special impl of set
doSomething(s1) ;
doSomething(s2) ;
How would ?1? and ?2? be defined and/or implemented ??
Or is the above just not possible (you are stuck with one
impl of every STL type in every program - whatever that may be) ??
Regards
template <typename SetType>
void doSomething(const SetType& theSet)
{
SetType::iterator iter = theSet.begin();
// ...
}
> std::set<int> s1 ; // the standard STL impl
> ?2? s2 ; // the special impl of set
MySet<int> s2;
> doSomething(s1);
> doSomething(s2);
This is exactly how things like std::sort can work on
e.g. either std::queue<T> or std::vector<T> or built-in
arrays.
<nitpicking>
typename SetType::const_iterator iter = theSet.begin();
</nitpicking>
> // ...
> }
--
Thomas