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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| #include <boost\mpl\vector.hpp>
#include <boost\mpl\accumulate.hpp>
#include <boost\mpl\bool.hpp>
#include <boost\mpl\and.hpp>
#include <boost\mpl\next_prior.hpp>
#include <boost\mpl\placeholders.hpp>
#include <boost\mpl\if.hpp>
using boost::mpl::placeholders::_1;
using boost::mpl::placeholders::_2;
struct Data1{};
struct Data2{};
struct Data3{};
struct Data4{};
struct OP1{};
struct OP2{};
struct OP3{};
struct OP4{};
template<class T>
struct DataHelper;
typedef boost::mpl::bool_<true> DataActivated;
typedef boost::mpl::bool_<true> DataNotActivated;
template<> struct DataHelper<Data1> : DataActivated {};
template<> struct DataHelper<Data2> : DataNotActivated {};
template<> struct DataHelper<Data3> : DataActivated {};
template<> struct DataHelper<Data4> : DataNotActivated {};
template<typename data_, typename op_, bool activated_>
struct OP_trait
{
typedef data_ type_data;
typedef op_ type_op;
typedef boost::mpl::bool_<activated_> activated;
};
template<typename data_>
struct is_data_activated
{
typedef typename DataHelper<data_>::type type;
};
template<class trait_op>
struct check_op
{
private:
typedef typename boost::mpl::accumulate<
typename trait_op::type_data
, boost::mpl::bool_<true>
, boost::mpl::and_< is_data_activated<_2>,_1 >
>::type data_activated_type;
public:
typedef typename boost::mpl::if_<
typename trait_op::activated
,data_activated_type
,boost::mpl::bool_<true>
>::type type;
static const bool value = type::value;
};
typedef OP_trait<boost::mpl::vector<Data1,Data3>, OP1,true> trait_op1; //op1 liée à Data1 et Data3
static_assert(check_op<trait_op1>::value,"error op 1");
typedef OP_trait<boost::mpl::vector<Data1,Data2>, OP2,true> trait_op2; //op2 liée à Data1 et Data2
static_assert(check_op<trait_op2>::value,"error op 2");
typedef OP_trait<boost::mpl::vector<Data3>, OP3,true> trait_op3; //op3 liée à Data3
static_assert(check_op<trait_op3>::value,"error op 3");
typedef OP_trait<boost::mpl::vector<Data4,Data2>, OP4,false> trait_op4;//op4 liée à Data4 et Data2
static_assert(check_op<trait_op4>::value,"error op 4");
int main()
{
return 0;
} |
Partager