在Scala中模拟可变模板 [英] Emulating variadic templates in Scala

查看:145
本文介绍了在Scala中模拟可变模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设你想要像可变模板(定义n类参数的能力一个通用类)在Scala中。

Suppose you want to have something like variadic templates (the ability to define n type parameters for a generic class) in Scala.

例如,您不想定义 Tuple2 [+ T1,+ T2] Tuple3 [+ T1,+ T2,+ T3] 元组[T *]

For example you do not want to define Tuple2[+T1, +T2] and Tuple3[+T1, +T2, +T3] but Tuple[T*].

是否有其他选项,而不是主题者,这将支持元组,产品和功能?

Are there other options than HLists that would support Tuple, Product and Function?

推荐答案

目前Scala中没有任何语法构造,可以让您建议。这也是为什么有22个元组(Tuple2,Tuple3,...,Tuple22)以及不同的Function类(Function0,...)的原因。

At the moment there's no syntactical construct in Scala which allows what you're suggesting. That's also the reason why there are 22 Tuple classes (Tuple2, Tuple3, ..., Tuple22) and also different Function classes (Function0, ...).

这篇关于在Scala中模拟可变模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆