实现左右折叠的可变参数模板的最佳方法是什么
的形式
template<typename ...args>
void func(int l, args... arg, int r){
}
我正在尝试实现一些我可以使用
template<typename ...args>
void func(int l, int r, args... arg){
}
,但这会使它使用起来更加不直观。 该函数本身是
template<typename ...TA, enable_if_t<sizeof...(TA) == 2 * (d - 1), int> = 0>
void upd(int u1, TA... args, T val){
u1 += n;
while(u1){
t[u1].upd(args..., val);
u1 >>= 1;
}
}
I'm trying to implement something of the form
template<typename ...args>
void func(int l, args... arg, int r){
}
I could use
template<typename ...args>
void func(int l, int r, args... arg){
}
but it would make it far more unintuitive to use.
The function itself is
template<typename ...TA, enable_if_t<sizeof...(TA) == 2 * (d - 1), int> = 0>
void upd(int u1, TA... args, T val){
u1 += n;
while(u1){
t[u1].upd(args..., val);
u1 >>= 1;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
d
似乎是固定的,因此它并不是真正的可变参数。然后您可以进行专门化(达到一定限制)
如果类型 T1、TN 是固定的(假设
SomeType
),一种可能性是使用std::index_sequence
而不是d
否则,您可以使用用于实现的元组或重新排序参数,并为接口提供包装器:
d
seems fixed, so it is not really variadic.You can then have specializations (up to a certain limit)
If the types T1, TN are fixed (assuming
SomeType
), one possibility is to usestd::index_sequence
instead ofd
Else, you can use tuple or reordering argument for implementation, and provide wrapper for the interface: