템플릿이 템플릿 유형 매개 변수 내부에있을 때 템플릿 매개 변수로 템플릿을 호출하는 방법 :
template<template<class> class Template, class T>
struct MakeType
{
using type = Template<T>;
};
template<class Policy>
struct Blah
{
using type = MakeType< /*A non-instantiated template member in Policy*/, int>::type;
};
예를 들어 Policy
템플릿 멤버가있을 수 있습니다 ArrayType
.
class ExamplePolicy
{
template<class T>
using ArrayType = std::vector<T>;
};
어떻게 부릅니까 MakeType
템플릿과 어쩌구에서 Policy::ArrayType
등 Template
.
MakeType
직접 호출 이 잘 작동합니다.
static_assert(std::is_same_v<std::vector<int>, MakeType<std::vector, int>::type>);
컴파일할까요
이것이 문제를 해결합니까?
// -*- compile-command: "g++ SO.cpp"; -*-
#include <vector>
template <template <class> class Template, class T>
struct MakeType
{
using type = Template<T>;
};
template <class Policy>
struct Blah
{
using type = typename MakeType<Policy::template ArrayType, int>::type;
type foo()
{
return type();
}
};
struct ExamplePolicy
{
template <class T>
using ArrayType = std::vector<T>;
};
int main()
{
Blah<ExamplePolicy> blah;
auto tmp = blah.foo();
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다