gpt4 book ai didi

c++ - 如何使用 pack 作为模板参数实例化专门的模板类?

转载 作者:行者123 更新时间:2023-11-28 04:21:41 24 4
gpt4 key购买 nike

我从 Template with Multiple pack as input parameter 中获取了以下示例.

#include <iostream>
#include <tuple>

// A template to hold a parameter pack.
template < typename... >
struct Typelist {};

// Declaration of a template with multiple parameter pack.
template< typename TypeListOne
, typename TypeListTwo
>
struct SomeStruct;

// Specialization of template with multiple parameter packs
template< typename... TypesOne
, typename... TypesTwo
>
struct SomeStruct< Typelist < TypesOne... >
, Typelist < TypesTwo... >
>
{
// Can use TypesOne... and TypesTwo... how ever
// you want here. For example:
typedef std::tuple< TypesOne... > TupleTypeOne;
typedef std::tuple< TypesTwo... > TupleTypeTwo;
};

我想知道如何实例化 SomeStruct 的对象。

最佳答案

例如:

SomeStruct <Typelist <char, int, char>,
Typelist <int, double>> var;

关于c++ - 如何使用 pack 作为模板参数实例化专门的模板类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55308356/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com