mercredi 3 novembre 2021

Unpakc two vectors in a varidic template function and cast type

I have 2 vectors;

std::vector<std::string> a = {"12", "2.0", "name"};
std::vector<std::string> b = {"int", "double", "string"}

These two vectors' lengths are equal but not certain.

How can I pass these two vectors to a variadic template function like this?

template <typename... Args>
Func(Args... args) {}

Unpack(Func, a, b) --> Func(int, double, std::string)

Sorry I didn't express this question very clearly.

I describe my project's scenery.

I am writing an HTTP server router.

router.Get("/path/<int>/<double>", [](int a, double b) {
    std::cout << a << " " << b << std::endl;
}

I register this handler with this route path.

When the server gets the "/path/12/2.0" route path, I will get two vectors, one is a(value vector) and another is b (type vector).

Then I want to pass these parameters to the handler which is varidic template callback.

Aucun commentaire:

Enregistrer un commentaire