【问题标题】:aliasing template to template argument别名模板到模板参数
【发布时间】:2015-08-15 12:25:36
【问题描述】:

此代码来自Phobos的源代码。

// This template simply aliases itself to R and is useful for consistency in
// generic code.
template Take(R)
if (isInputRange!(Unqual!R) &&
((!isInfinite!(Unqual!R) && hasSlicing!(Unqual!R)) || is(R T == Take!T)))
{
    alias Take = R;
}

但它是什么意思/它做什么/什么时候有用?

【问题讨论】:

    标签: templates range alias d


    【解决方案1】:

    经过约束检查,模板实际上是一个恒等函数;也就是说,is(Take!MyRange == MyRange) 为真。

    约束检查 R 是否为输入范围,是否为无限且具有切片,或者是否已经是 Take 范围。

    【讨论】:

      猜你喜欢
      • 2017-01-20
      • 1970-01-01
      • 2014-01-29
      • 2017-09-22
      • 1970-01-01
      相关资源
      最近更新 更多