1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
template < bool /*allow_specialisation */, typename... P > struct event_base // primary template
{
void foo( P... ) const { std::cout << "event(primary)::foo()\n" ; }
void bar( P... ) const { std::cout << "event(primary)::bar()\n" ; }
void foobar( P... ) const { std::cout << "event(primary)::foobar()\n" ; }
};
template <> struct event_base< true, char, int > // explicit specialisation
: private event_base< false, char, int > // base class is the primary template
{
// specialised foo
void foo( char, int ) const { std::cout << "event(explicit specialisation)::foo()\n" ; }
using event_base<false,char,int>::bar ; // delegate to inherited primary bar
using event_base<false,char,int>::foobar ; // delegate to inherited primary foobar
};
template < typename... P > using event = event_base<true,P...> ;
int main()
{
event<char,int> eci ;
eci.foo( 'a', 5 ) ; // specialised
eci.bar( 'a', 5 ) ; // primary
eci.foobar( 'a', 5 ) ; // primary
}
|