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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <type_traits>
#include <iosfwd>
template < typename FIRST = int, typename SECOND = double,
typename THIRD = void, typename FOURTH = char >
struct example { /* ... */ };
enum param { FIRST, SECOND, THIRD, FOURTH };
namespace detail
{
template < param, typename > struct example_maker ;
template < typename TYPE > struct example_maker<FIRST,TYPE>
{ using type = example<TYPE> ; } ;
template < typename TYPE > struct example_maker<SECOND,TYPE>
{ using type = example<int,TYPE> ; } ;
template < typename TYPE > struct example_maker<THIRD,TYPE>
{ using type = example<int,double,TYPE> ; } ;
template < typename TYPE > struct example_maker<FOURTH,TYPE>
{ using type = example<int,double,void,TYPE> ; } ;
}
template < param PARAM, typename TYPE >
using example_t = typename detail::example_maker<PARAM,TYPE>::type ;
int main()
{
example_t< FIRST, long > ex1 ; // example< FIRST = long >
static_assert( std::is_same< decltype(ex1), example<long> >::value ) ;
example_t< SECOND, short > ex2 ; // example< SECOND = short >
static_assert( std::is_same< decltype(ex2), example<int,short> >::value ) ;
example_t< THIRD, char > ex3 ; // example< THIRD = char >
static_assert( std::is_same< decltype(ex3), example<int,double,char> >::value ) ;
example_t< FOURTH, std::ostream& > ex4 ; // example< FOURTH = std::ostream& >
static_assert( std::is_same< decltype(ex4), example<int,double,void,std::ostream&> >::value ) ;
}
|