Re: matching multiple template
On Jul 9, 6:37 am, "Eric Pruneau" <eric.prun...@cgocable.ca> wrote:
"abir" <abirba...@gmail.com> a =E9crit dans le message de news:
385bd2d8-d853-4e2d-bdad-35005952b...@p25g2000hsf.googlegroups.com...
i have atemplate
template<typename S> class Indexer{};
i want to have a specialization for std::vector bothconst&nonconst
version.
template<typename T,typename A> class Indexer<std::vector<T,A> > {}
matches only with nonconst version. anyway to match it for both? and
get if it isconstor nonconst?
Actually i want 2 specialization, one for std::vector<T,A>const&non
constother for std::deque<T,A>const&nonconst.
thanks
abir
I'm not sure if I understand what you really want to do but here is what =
I
think.
you have a class
template<typename S>
class Indexer{ };
and you want to specialize this class when S is a vector and when S is ac=
onstvector (samething with deque).
Here is how to do that. Note that I've removed the allocatortemplate
parameter to simplify the example but I amsure you will find a way to
integrate it!!!
template<typename T, typename CONT>
struct Indexer
{
Indexer() { cout <<"1\n"; }
};
template<typename T>
struct Indexer<T, vector<T> >
{
Indexer() { cout <<"2\n"; }
};
template<typename T>
struct Indexer<T,constvector<T> >
{
Indexer() { cout <<"3\n"; }
};
template<typename T>
struct Indexer<T, deque<T> >
{
Indexer() { cout <<"4\n"; }
};
template<typename T>
struct Indexer<T,constdeque<T> >
{
Indexer() { cout <<"5\n"; }
};
int main()
{
Indexer<int, vector<int> > a; // print 2
Indexer<int, deque<int> > b; // print 4
Indexer<int, vector<int>const> c; // print 3
Indexer<int, deque<int>const> d; // print 5
return 0;
}
------------------------
Eric Pruneau
Thanks for answering.
Actually this is what i have already. What i want is to match both
const & non const version in same specialization something like (this
is not a valid syntax of course),
template<typename T>
struct Indexer<T,const vector<T> | vector<T> >
{
Indexer() { cout <<"3\n"; }
};
so i want both the match to succeed in same specialization. Also i
need to know which match is there.
i don't know if it is directly possible, but i am thinking having a
proxy class to delegate the responsibility.
thanks
abir