首页 \ 问答 \ 模板元编程,使用可变模板:编译器错误(Template Meta-programming, with Variadic Templates: compiler error)

模板元编程,使用可变模板:编译器错误(Template Meta-programming, with Variadic Templates: compiler error)

我第一次尝试variadic模板元编程,并一直得到一个编译器错误,我一直无法追查。

我遵循这个页面上的“元组”示例(尽管我将对象称为ItemSet

ItemSet部分编译得很好:

template<typename...Ts> class ItemSet { };

template<typename item_T, typename ...Ts>
class ItemSet<item_T, Ts...> : public ItemSet<Ts...>
{
public:
    ItemSet(item_T t, Ts... item_types) : ItemSet<Ts...>(item_types...), tail(t) { }

protected:
    item_T tail;
};





template <typename...M> struct type_holder;

template<typename T, typename ...M>
struct type_holder<0, ItemSet<T, M...>>
{                          // ERROR: M parameter pack expects a type template argument.
    typedef T type;
};

template <int k, typename T, typename ...M>
struct type_holder<k, ItemSet<T, M...>>
{
    typedef typename type_holder<k - 1, ItemSet<M...>>::type type;
};




int main()
{
    ItemSet<int, string, string, double> person(0, "Aaron", "Belenky", 29.492);
}

但是,在注释掉的代码中,我在type_holder的声明处得到编译器错误。 我已经在相同的语法上尝试了一些变体,但始终存在相同的问题。

我正在使用Microsoft Visual Studio 2013,它应该完全支持模板编程和变量模板。

你知道编译器错误是什么,你能解释一下吗?


I'm attempting variadic template meta programming for the first time and consistently getting a compiler error that I have not been able to track down.

I'm following the "tuple" example on this page (although I'm calling my object an ItemSet)

The ItemSet part compiles just fine:

template<typename...Ts> class ItemSet { };

template<typename item_T, typename ...Ts>
class ItemSet<item_T, Ts...> : public ItemSet<Ts...>
{
public:
    ItemSet(item_T t, Ts... item_types) : ItemSet<Ts...>(item_types...), tail(t) { }

protected:
    item_T tail;
};





template <typename...M> struct type_holder;

template<typename T, typename ...M>
struct type_holder<0, ItemSet<T, M...>>
{                          // ERROR: M parameter pack expects a type template argument.
    typedef T type;
};

template <int k, typename T, typename ...M>
struct type_holder<k, ItemSet<T, M...>>
{
    typedef typename type_holder<k - 1, ItemSet<M...>>::type type;
};




int main()
{
    ItemSet<int, string, string, double> person(0, "Aaron", "Belenky", 29.492);
}

However, in the commented out code, I get the compiler error at the declaration of type_holder. I've tried a bunch of variations on the same syntax, but always with the same issue.

I'm using Microsoft Visual Studio 2013, which is supposed to have full support for Template programming and Variadic Templates.

Do you understand what the compiler error is, and can you explain it to me?


原文:https://stackoverflow.com/questions/27487470
更新时间:2023-10-25 13:10

最满意答案

字体的大小取决于两种质量。 例如,这里非常明显的是它增加了百分比: http : //jsfiddle.net/EQ3vF/1/

结果是完整字体大小的百分比。


The size of the font depends on both qualities. For example, it is very evident here what the em adds to the percentage: http://jsfiddle.net/EQ3vF/1/

The result is a percentage of the full font-size.

相关问答

更多
  • 伪代码: // stack of Key class Stack { class Element { int prio, Key elem; }; MaxPriorityQueue q; int top_priority = 0; void push(Key x) { q.push(Element(top_priority++, x)); } Key pop() { top_priority--; return q.pop().elem; } }; ...
  • 属性选择器同样特定于类选择器。 如果你想覆盖你可以这样编写的类: input.text-style[type="text"] 检查此决定了解更多属性选择器的特异性是什么? 阅读http://www.w3.org/TR/selectors/#specificity Attribute selectors are equally specific to class selectors. if you want to override the class your can write like this: in ...
  • vs ?( vs ?)[2023-02-11]

    是的,将“强调”的定义与“强调”进行比较是非常流行的。 唯一的标准定义是“ 强调 ,但更多 !!”。 就个人而言,我使用进行正常的强调,在那里你会用不同的语调读出强调的单词,而对于那些你把关键词和短语从文本中挑选出来的人来说,文本挑选主题。 这不是一个标准的解释,而是通过默认的斜体/粗体样式使其有意义和适当地呈现。 无论你做什么, 都要一致 。 Yeah, the definition of what ‘strong emphasis’ is compared to just ‘emphasis’ ...
  • 说一个是比另一个更好的选择是错误的(或者两者都不会在规范中被赋予自己的目的)。 甚至可能值得注意的是,StackOverflow广泛使用px单位。 被告知这不是糟糕的选择。 单位的定义 px是一个绝对的测量单位(如, pt或cm ),也恰好是单位的1/96(更多的是为什么稍后)。 因为它是一个绝对的测量,它可以在任何时候想要定义一些特定的大小,而不是与浏览器窗口的大小或字体大小成比例。 像所有其他绝对单位一样, px单位根据浏览器窗口的宽度不会缩放。 因此,如果您的整个页面设计使用绝对单位,如px而不是% ...
  • 您可以使用std::set作为优先级队列而不重复。 top元素可以通过rbegin()找到。 渐近复杂度与二进制堆相同:O(1) top符合rbegin ,O(lg n ) push和O(lg n ) pop的标准要求。 但是,常数会更高。 至于过滤器,我建议你使用自定义push方法(无论如何这是一个好主意)将std::set包装在一个类中,为你运行过滤谓词。 You can use std::set as a priority queue without duplicates. The top eleme ...
  • #list div比#d2 #list div特异性 - 前者是一个ID +元素,后者只是一个ID。 因此,在#list div中明确定义的#d2中的任何样式都将被后者选择器覆盖。 div#d2将具有同样的特异性,因为#list div和#list #d2具有更高的特异性。 特殊性层次结构的顺序是!important样式,内联样式,ID,类和元素。 假单元和假单元具有真实类别或元素的特征。 层次结构中的每个步骤都会覆盖它下面的所有步骤,因此具有10个类的选择器仍然会被一个单一ID的选择器覆盖。 CSS选择器 ...
  • 字体的大小取决于两种质量。 例如,这里非常明显的是它增加了百分比: http : //jsfiddle.net/EQ3vF/1/ 结果是完整字体大小的百分比。 The size of the font depends on both qualities. For example, it is very evident here what the em adds to the percentage: http://jsfiddle.net/EQ3vF/1/ The result is a percentage ...
  • 绕过引文。 围绕着强调的文字。 它们对搜索引擎和屏幕阅读器等语义有完全不同的含义。 goes around citations. goes around emphasised text. They have totally different semantic meanings to things like search engines and screen readers.
  • 这些是在更改密钥时需要执行的二进制堆上的操作。 优先级队列中的每个“节点”都保存在二进制堆中。 当您添加项目时,该项目需要位于正确的位置,因此“二进制堆的规则”不会被破坏。 更改密钥时也会发生同样的情况,您需要更改项目在优先级堆中的位置,以便不破坏规则(该项目的子项不大于该项目,并且该项目的父项不小)。 这个优先级队列是用二进制堆实现的,这意味着它基于二叉树,这就是为什么你可以在这些方法中看到除以2的原因,因为它需要逐层上下项目,这是由该部门实现的(第一级有一个节点,第二级有两个节点,第三级有四个节点等,每 ...
  • 练习所指的程序是一种称为自我训练的无监督学习。 我们的想法是,您使用整个标记的trainign集来构建模型。 然后,您收集更多未标记的数据。 找到新的未标记数据要比找到新的标记数据容易得多。 之后,您将使用最初训练的模型标记新数据。 现在,使用自动生成的标签,训练新模型。 The procedure that the exercise is referring to is a type of unsupervised learning known as self-training. The idea is ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。