使用模板参数推导类的"outer class"

Deducing the "outer class" of a class with Template Argument Deduction

本文关键字:outer class 参数      更新时间:2023-10-16
class Component_Base{};
class Rect_Component : Component_Base
{
public:
struct Info
{
uInt width;
uInt height;
};
};
template<typename... Args>
class ECSData
{
private:
tuple<optional_ECSVector_wrapped_t<Args>...> data;
public:
template<typename... Info>
void createEntity(Info&&... info) {
}
};
int main()
{
ECSData<Rect_Component, Text_Component, Rendering_System> ecsData;
ecsData.createEntity(Rect_Component::Info{ .width{200}, .height{500} });
return 0;
}

在上面的代码中,我将Rect_Component::Info传递给createEntity(). 给定上面的代码,是否可以在createEntity()内部让模板参数推导推断T::Info中的T是什么,并使用所说的 T? 毕竟我在电话中写Rect_Component,所以我怀疑一定有办法

考虑:

struct Not_Rect_Component {
using Info = Rect_Component::Info;
};

这无法与原始Rect_Component提供的Info区分开来,因此您无法推断出其中之一。您必须在Info中提供一个 typedef,它引用正确的父类型。