Здравствуйте, What, Вы писали:
#include "stdafx.h"
struct default_policy_1{};
struct default_policy_2{};
struct default_policy_3{};
struct default_polices
{
typedef default_policy_1 policy_1;
typedef default_policy_2 policy_2;
typedef default_policy_3 policy_3;
};
template<class T>
struct policy_1_is:virtual default_polices
{
typedef T policy_1;
};
template<class T>
struct policy_2_is:virtual default_polices
{
typedef T policy_2;
};
template<class T>
struct policy_3_is:virtual default_polices
{
typedef T policy_3;
};
template<int ID>
struct default_polices_arg:virtual default_polices
{};
template
<class Policy_1
,class Policy_2
,class Policy_3
>
struct polices_discriminator
:Policy_1
,Policy_2
,Policy_3
{};
template
<class Policy_1=default_polices_arg<1>
,class Policy_2=default_polices_arg<2>
,class Policy_3=default_polices_arg<3>
>
struct some_class
{
typedef polices_discriminator
<Policy_1
,Policy_2
,Policy_3
> policy;
typedef typename policy::policy_1 policy_1;
typedef typename policy::policy_2 policy_2;
typedef typename policy::policy_3 policy_3;
};
template<class T>
void polices_print()
{
std::cout<<typeid(typename T::policy_1).name()<<std::endl;
std::cout<<typeid(typename T::policy_2).name()<<std::endl;
std::cout<<typeid(typename T::policy_3).name()<<std::endl;
std::cout<<std::endl;
}
int main()
{
polices_print<some_class<> >();
polices_print<some_class<policy_1_is<int>, policy_3_is<char> > >();
return 0;
}
вывод
struct default_policy_1
struct default_policy_2
struct default_policy_3
int
struct default_policy_2
char
Press any key to continue
... << RSDN@Home 1.1.3 beta 1 >>