2015-08-15 123 views
1

此代碼是來自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; 
} 

但這是什麼意思/它做什麼/什麼時候有用?

回答

1

經過約束檢查,模板實際上是一個身份函數;即is(Take!MyRange == MyRange)爲真。

約束檢查R是否是輸入範圍,以及它是無限且已切片,還是已經是Take範圍。