restrict (C++ AMP)

限制規範可以套用到函式和 Lambda 宣告。 它會在函式中的程式碼上強制執行限制,以及在使用 C++ Accelerated Massive Parallelism (C++ AMP) 的應用程式中函式的行為上強制執行限制。

注意

如需屬於儲存體類別屬性之 __declspec 關鍵字的相關資訊 restrict ,請參閱 restrict

restrict 句採用下列形式:

子句 描述
restrict(cpu) 函式可以使用完整的 C++ 語言。 只有使用 restrict(cpu) 函式宣告的其他函式可以呼叫函式。
restrict(amp) 函式只能使用 C++ AMP 可以加速之 C++ 語言的子集。
restrict(cpu)restrict(amp) 的序列。 函式必須同時符合 restrict(cpu)restrict(amp) 的限制。 函式可由使用 restrict(cpu)restrict(amp)restrict(cpu, amp)restrict(amp, cpu) 宣告的函式呼叫。

restrict(A) restrict(B) 格式可以撰寫為 restrict(A,B)

備註

關鍵字 restrict 是內容關鍵字。 限制規範、cpuamp 不是保留字。 規範的清單無法擴充。 沒有 子句的 restrict 函式與具有 restrict(cpu) 子句的函式相同。

內含 restrict(amp) 子句的函式具有下列限制:

  • 函式只會呼叫內含 restrict(amp) 子句的函式。

  • 函式必須為可內嵌。

  • 函式只能宣告 、 intunsigned intfloatdouble 變數,以及只包含這些類型的類別和結構。 bool 也允許,但如果您在複合類型中使用它,它必須是 4 位元組對齊。

  • Lambda 函式無法透過參考方式擷取,也無法擷取指標。

  • 參考和單一間接取值指標只支援區域變數、函式引數和傳回型別。

  • 不允許使用下列各項:

    • 遞迴。

    • 以 volatile 關鍵字宣告的 變數。

    • 虛擬函式。

    • 函式的指標。

    • 成員函式的指標。

    • 結構中的指標。

    • 指標的指標。

    • goto 陳述式。

    • 標記陳述式。

    • trycatchthrow 語句。

    • 全域變數。

    • 靜態變數。 請改用 tile_static Keyword

    • dynamic_cast 轉換。

    • typeid 運算子。

    • asm 宣告。

    • Varargs。

如需函式限制的討論,請參閱 restrict(amp) 限制

範例

下列範例示範如何使用 restrict(amp) 子句。

void functionAmp() restrict(amp) {}
void functionNonAmp() {}

void callFunctions() restrict(amp)
{
    // int is allowed.
    int x;
    // long long int is not allowed in an amp-restricted function. This generates a compiler error.
    // long long int y;

    // Calling an amp-restricted function is allowed.
    functionAmp();

    // Calling a non-amp-restricted function is not allowed.
    // functionNonAmp();
}

另請參閱

C++ AMP (C++ Accelerated Massive Parallelism)