Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > how would one define/use polymorphic implementations of STL types??

Reply
Thread Tools

how would one define/use polymorphic implementations of STL types??

 
 
Coder Fodder
Guest
Posts: n/a
 
      02-04-2010
Hello there.

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
 
Reply With Quote
 
 
 
 
Gert-Jan de Vos
Guest
Posts: n/a
 
      02-04-2010
On Feb 4, 3:01*pm, Coder Fodder <(E-Mail Removed)> wrote:
> Hello there.
>
> 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() ;
> * * // ...
> }


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.
 
Reply With Quote
 
 
 
 
Thomas J. Gritzan
Guest
Posts: n/a
 
      02-04-2010
Am 04.02.2010 16:40, schrieb Gert-Jan de Vos:
> On Feb 4, 3:01 pm, Coder Fodder <(E-Mail Removed)> wrote:
>> 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() ;
>> // ...
>> }

>
> template <typename SetType>
> void doSomething(const SetType& theSet)
> {
> SetType::iterator iter = theSet.begin();


<nitpicking>
typename SetType::const_iterator iter = theSet.begin();
</nitpicking>

> // ...
> }


--
Thomas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
an oddball scary kind of thing you would think would never happen richard Computer Support 4 01-31-2010 06:34 PM
Sources for checked STL implementations? A. W. Dunstan C++ 2 05-10-2006 04:02 PM
Copy elements from one STL container to another STL container Marko.Cain.23@gmail.com C++ 4 02-16-2006 05:03 PM
Struts/JSP - How would one view multiple database records over severalpages instead of one? Geoff Winsor Java 3 01-29-2005 03:31 AM



Advertisments