模板元编程,使用可变模板:编译器错误(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
最满意答案
字体的大小取决于两种质量。 例如,这里非常明显的是它增加了百分比: 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; } }; ... -
CSS选择器优先级(CSS selector priority)[2023-04-24]
属性选择器同样特定于类选择器。 如果你想覆盖你可以这样编写的类: 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’ ... -
为什么em而不是px?(Why em instead of px?)[2024-03-19]
说一个是比另一个更好的选择是错误的(或者两者都不会在规范中被赋予自己的目的)。 甚至可能值得注意的是,StackOverflow广泛使用px单位。 被告知这不是糟糕的选择。 单位的定义 px是一个绝对的测量单位(如, pt或cm ),也恰好是单位的1/96(更多的是为什么稍后)。 因为它是一个绝对的测量,它可以在任何时候想要定义一些特定的大小,而不是与浏览器窗口的大小或字体大小成比例。 像所有其他绝对单位一样, px单位根据浏览器窗口的宽度不会缩放。 因此,如果您的整个页面设计使用绝对单位,如px而不是% ... -
高级优先级队列(Advanced priority queue)[2022-04-24]
您可以使用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 ... -
选择器的CSS优先级(CSS priority of selectors)[2022-04-10]
#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 ...
-
为什么当我有时(Why a when I have )[2023-10-15]
绕过引文。 围绕着强调的文字。 它们对搜索引擎和屏幕阅读器等语义有完全不同的含义。 goes around citations. goes around emphasised text. They have totally different semantic meanings to things like search engines and screen readers. -
这些是在更改密钥时需要执行的二进制堆上的操作。 优先级队列中的每个“节点”都保存在二进制堆中。 当您添加项目时,该项目需要位于正确的位置,因此“二进制堆的规则”不会被破坏。 更改密钥时也会发生同样的情况,您需要更改项目在优先级堆中的位置,以便不破坏规则(该项目的子项不大于该项目,并且该项目的父项不小)。 这个优先级队列是用二进制堆实现的,这意味着它基于二叉树,这就是为什么你可以在这些方法中看到除以2的原因,因为它需要逐层上下项目,这是由该部门实现的(第一级有一个节点,第二级有两个节点,第三级有四个节点等,每 ...
-
关于使用EM训练HMM(About training HMM by using EM)[2022-05-02]
练习所指的程序是一种称为自我训练的无监督学习。 我们的想法是,您使用整个标记的trainign集来构建模型。 然后,您收集更多未标记的数据。 找到新的未标记数据要比找到新的标记数据容易得多。 之后,您将使用最初训练的模型标记新数据。 现在,使用自动生成的标签,训练新模型。 The procedure that the exercise is referring to is a type of unsupervised learning known as self-training. The idea is ...