D
D
Daniel2021-08-03 21:01:44
C++ / C#
Daniel, 2021-08-03 21:01:44

How to convert one variadic template to another variadic template?

How to convert one variadic templates into another, with a different number of parameters, according to a certain rule? (the code illustrates the problem)

struct A{
int i;
std::string s;
unsigned int u;
};
/*функция времени выполнения  что задаёт 
правило по преобразованию <А> в <int, std::string>
*/

template<typename Arg...>
struct Types;

auto types_new=foo<A,float,A>();//вернёт Types<int,std::string,float,int,std::string>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniel, 2021-08-09
@Porohovnik

https://en.cppreference.com/w/cpp/utility/tuple/tu...
using this function, and a rule of the form:

//пользовательское
template<> constexpr auto Type_to<>(glm::vec3 vec){
    return std::tuple(vec.x,vec.y,vec.z);

//для любого типа
    template<typename T>
    constexpr auto Type_to(T value){
        return value;
    }
};

and writing a function of the form:
template<typename ...Arg>
    constexpr auto foo(){
        return  std::tuple_cat{std::make_tuple<Arg>...,""};
    }

you can get almost the desired result (there is one extra type at the end, but it's easy to remove it)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question