简体   繁体   English

c ++模板结构“使用类型= struct_name”

[英]c++ template struct “using type = struct_name”

template <::size_t... Is>
struct int_pack {
  using type = int_pack;
};
  1. why do we need using type = int_pack here ? 为什么我们需要在这里using type = int_pack
  2. When we use a pattern like using type = struct_name , is there any specific usage ? 当我们使用诸如using type = struct_name的模式时,是否有任何特定用法?

You don't need using type = int_pack , it's just a shorter way to write int_pack . 您不需要using type = int_pack ,这只是编写int_pack一种较短方法。

type is usually used in type_traits for meta programming. type通常在type_traits用于元编程。 For example, std::enable_if defines a name type if it's template argument is true . 例如,如果std::enable_if的模板参数为true则定义一个名称type There are more of these helper functions/structures that define a name type . 这些帮助程序功能/结构中有更多定义名称type It's just a name that has stuck, like using i in a for loop index. 它只是一个名字,就像在for循环索引中使用i一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM