dimanche 2 juillet 2017

Store complex template type and use it as argument later on

I have an API function (ConstructFoo) that returns variadic template object I need to store and use later on as argument for other API function (useFoo). I need to do that arbitrary amount of times (like n-times, not known at compile time).

I can jiggle the moment for calling ConstructFoo (it is the part of builder pattern) but I have to call all useFoo at once at final step.

So far I experiment this:

auto foo = []() { return ConstructFoo<Bar>(); };
// Some time later:
useFoo(foo());

But I cannot store foo as the member (useFoo may come in another method).

Explanation: I am trying to get done builder pattern for this API. Language: C++ 17

Aucun commentaire:

Enregistrer un commentaire