In one project I have found a possibility to stay DRY as a lot of code except for some small parts could stay the same for template specialisations of a template. Here is a small working example what I'm currently doing to check which templated class I'm using:
template<typename T>
class A{};
template<typename T>
class B{};
template<template<class> class C>
void do_stuff()
{
if(std::is_same<A<int>,C<int>>::value)
{
// Do Stuff for A
} else if(std::is_same<B<int>,C<int>>::value)
// Do Stuff for B
}
}
int main()
{
do_stuff<A>();
}
What I would like to do instead is using
std::is_same<A,C>::value
to determine the template type. Is there any function that could help me or am I missing a pattern that would work better in this case?
I see that I could do something like
template<template<class> class C, typename T>
void do_stuff();
do_stuff<A,T>();
but that seems like the wrong way to do for me.
Aucun commentaire:
Enregistrer un commentaire