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 84 85 86 87
|
#include <tuple>
#include <iostream>
#include <vector>
#include <tuple>
#include <string>
#include <typeinfo>
template <size_t...>
struct index_tuple {};
template <size_t Sp, class IntTuple, size_t Ep>
struct make_index_tuple_imp;
template <size_t Sp, size_t... Indices, size_t Ep>
struct make_index_tuple_imp<Sp, index_tuple<Indices...>, Ep>
{
typedef typename make_index_tuple_imp<Sp+1, index_tuple<Indices..., Sp>, Ep>::type type;
};
template <size_t Ep, size_t ...Indices>
struct make_index_tuple_imp<Ep, index_tuple<Indices...>, Ep>
{
typedef index_tuple<Indices...> type;
};
template <size_t Ep, size_t Sp>
struct make_index_tuple
{
typedef typename make_index_tuple_imp<Sp, index_tuple<>, Ep>::type type;
};
template<typename... Types>
struct to_index_tuple
{
typedef typename make_index_tuple<sizeof...(Types), 0>::type type;
};
template <typename T, typename U>
struct DrawAndPromptConditionObject
{
U launch()
{
std::cout << "launch " << typeid(U).name() << std::endl;
return U();
}
};
template <typename S, typename... Args>
class MultiDrawAndPromptConditionObject
{
public:
MultiDrawAndPromptConditionObject(const DrawAndPromptConditionObject<S, Args>&... DAndPConditions_):
DAndPConditions(DAndPConditions_...)
{
}
std::tuple<Args...> launch()
{
return launch_imp(typename to_index_tuple<Args...>::type());
}
private:
template <size_t... Idx>
std::tuple<Args...> launch_imp(index_tuple<Idx...>)
{
return std::make_tuple(std::get<Idx>(DAndPConditions).launch()...);
}
std::tuple<DrawAndPromptConditionObject<S, Args>... > DAndPConditions;
};
int main()
{
DrawAndPromptConditionObject<const std::vector<std::string> &, int> testHauteur;
DrawAndPromptConditionObject<const std::vector<std::string> &, int> testLargeur;
DrawAndPromptConditionObject<const std::vector<std::string> &, std::string> promptStr;
MultiDrawAndPromptConditionObject<const std::vector<std::string> &, int, int, std::string> m1(testHauteur, testLargeur, promptStr);
m1.launch();
} |
Partager