问题标签 [variadic-templates]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - 拆分可变参数模板参数
如何将可变参数模板参数分成两半?就像是:
c++ - “……”令牌是什么意思?即参数包上的双省略号运算符
在浏览 gcc 当前实现的新 C++11 标头时,我偶然发现了“......”标记。您可以检查以下代码是否可以正常编译[通过 godbolt.org]。
那么,这个令牌的含义是什么?
编辑:看起来问题标题中的“......”被修剪为“......”,我的意思是“......”。:)
c++ - 在元组上泛化 for_each 以接受可变数量的参数
目前,我有:
是否有可能通过可变参数模板来概括这一点,以采用任意数量的元组参数?
编辑:
以下是我将如何使用我无法定义的内容:
编辑:更改为使用右值引用和 std::forward
c++ - 这个可变参数模板示例有什么问题?
基类是:
派生类是这样的:
创建函数:
和例子:
我不断收到此错误:
我试图改变它,但我不知道如何解决。
那么,有什么问题呢?以及如何解决这个例子?
c++ - 将包含 initializer_list 的参数包扩展为构造函数
我打算shared_ptr
在即将到来的项目中使用很多,所以(不知道std::make_shared
)我想编写一个可变参数模板函数spnew<T>(...)
作为shared_ptr
-returning的替代new
。一切都很顺利,直到我尝试使用构造函数包含initializer_list
. 当我尝试编译下面的最小示例时,我从 GCC 4.5.2 得到以下信息:
奇怪的是,如果我std::make_shared
替换spnew
. 在任何一种情况下,当涉及到时,它似乎都错误地推断出参数initializer_list
,错误地将Args...
其视为空。这是示例:
这只是我的疏忽还是错误?
c++ - 可变参数模板函数中的 ostream 重载
我有一个可变参数函数,我想在第一个参数类型上重载。
但是这些函数的行为并不像预期的那样。
这里发生了什么?
为什么不重载分辨率选择我想要的功能?
有没有办法在没有大量元编程的情况下做到这一点?(我能够解决它,std::is_convertible
但解决方案比我上面显示的简单代码大得多)。
c++ - 将类模板实例化与其基类模板进行比较时,is_same 返回 false 吗?
*编辑:不知何故,我认为编译器正在创建B
as A<int, int, string>
,这导致我假设 is_same 应该如何评估它们,而不管继承/派生如何。我的错 :( 抱歉后来的误解 :\ *
制作一些元函数来检查我的自定义类型,并遇到了这个问题,但不确定我是否理解这里发生了什么。我想我可以通过将已知类型的 this_t 成员与传递的任何参数的 this_t 进行比较来解决它,但我只想了解为什么第一个和第三个 is_same 测试失败:
is_same 是否通过A<...>
基础进行区分?A<int, int, string>
和之间有什么明显区别B
?
c++11 - 可变参数模板参数包中类型的位置
我正在尝试 C++0x,我想知道如何解决出现的以下问题。我有一个可变参数模板类:
假设该函数对 m_storage 元组中与 SomeType 模板参数相对应的向量进行某种操作(如果没有,则编译时间失败)。怎么能做到这一点?
我的想法是在参数包中找到 SomeType 的索引,然后使用 std::get 获取适当的向量,但我不知道如何做第一部分。
c++ - 推导出参数包而不将其作为模板参数显式传递?
请原谅对 C++ 类型推导的任何无知,但我希望能够携带参数包的定义,以便稍后我可以测试内部类型。这可能吗?就像是:
哎?非?
c++ - Create static array with variadic templates
There was an answer on stackoverflow (which I can't seem to find anymore) which demonstrated how a variadic template can be used in C++11 to create a static array at compile time:
A recursive meta-function could be provided to instantiate array_
with any number of parameters, which will then be copied at compile time into the internal array. It's a useful way to create meta-functions for generating constant arrays at compile time.
However, one problem is that it depends on class template parameters to get the actual values to populate the array. This results in one major limitation: only integral constants can be used as value template parameters. So, you can't use this technique to generate arrays of custom types.
I tried to think of something to work around this limitation, but can't come up with anything. Is there any way to make this technique work with non-integral constants?