C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Template dispatching technique

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
APokorny
Guest





PostPosted: Sat Nov 26, 2005 2:48 pm    Post subject: Template dispatching technique Reply with quote



Hi,
Two days ago I noticed a gcc bug, which provides a nice dispatch
feature. Actually I only believe that it is a bug, I am not really sure
about that. With this email I would like to verify that this really is
a bug, and whether there are alternative techniques, which
behave similar.

struct basic_strategy {

template<typename A,typename Dummy = void>
struct implementation;

template<typename A>
struct implementation<A, boost::enable_if<..> > {
};
// ...
// several further partial specialization could follow here,

};

struct extended_strategy : basic_strategy {

templatet<typename A>
struct implementation<A,enable_if {
// do something extended in here
};

};

I can then either pass extended_strategy or basic_strategy
as a template parameter to an algorithm, which will then call
something from the implementation struct:

template<typename Strategy,typename A>
void an_algorithm( A & parameters );
{
Strategy::template implementation<A>::do_something();
}

When using gcc, the algorithm will only notice the partial
specializations defined inside of basic_strategy, if Strategy is
basic_strategy. When extended_strategy is used, it will
pick specializations from both scopes with the ones from
extended_strategy overriding the ones from basic_strategy.
But after some reading I believe that these partial
specializations in extended_strategy are forbidden.

Comeau does not accept the code. If extended_strategy
and basic_strategy are in different namespaces gcc will also
refuse to build that code. So now I work on simulating
that behaviour with augmented tag based dispatching.

Regards,
Andreas Pokorny


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Albert Jin
Guest





PostPosted: Sun Nov 27, 2005 5:55 pm    Post subject: Re: Template dispatching technique Reply with quote



Sounds that g++ allows specialization of a nested
internal template class at inherited class? I have no
idea then.

BTW. The best practice I have regarding to "simulating
that behaviour with augmented tag based dispatching"
is to use function overloading with a tag type. Some
code like this,

class foo {
private:
class my_tag1;
class my_tag2;

public:
void foo(my_tag1 *) {
// ...
}

void foo(my_tag2 *) {
// ...
}
};

The access of the two overloaded functions foo() are
actually controlled by the tag parameter, my_tag1
and my_tag2. The templated based implementation
for this is cumbersome and hard to make different
compilers happy.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.