3
#include <tuple>
class Foo {
public:
Foo(int i, double d, const char* str) { }
};
template<class T, class... CtorArgTypes>
class ObjectMaker {
public:
ObjectMaker(CtorArgTypes... ctorArgs) : m_ctorArgs(ctorArgs...)
{
}
Foo* create()
{
//What do I do here?
}
private:
std::tuple<CtorArgTypes...> m_ctorArgs;
};
int main(int, char**)
{
ObjectMaker<Foo, int, double, const char*> fooMaker(42, 5.3, "Hello");
Foo* myFoo = fooMaker.create(); //this should do new Foo(42, 5.3, "Hello");
}
는 기본적으로, Foo
의 생성자에 전달 될 인수를 저장하고 ObjectMaker::create()
를 호출 할 때 그들을 사용하는 클래스 ObjectMaker
를 원한다. 내가 알 수없는 것은 tuple
의 값을 Foo
의 생성자로 가져 오는 방법입니다.std :: tuple의 값을 함수 인수로 사용하려면 어떻게해야합니까?
[이 질문을 볼 수 있습니다 (http://stackoverflow.com/a/4121942/246886). –
일치하는 함수 포인터를 호출하는 튜플 [ "unpacking"가능한 중복] (http://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer) – Xeo
Btw 코드 마크 업을 위해 HTML 태그를 사용하지 말고, 인라인에는 백틱을, 코드 블록에는 네 개의 선행 공백 (또는 마크 및 Ctrl-K)을 사용하십시오. – Xeo