分享方式:


MatchEvent

C++ Build Insights SDK 與 Visual Studio 2017 和更新版本相容。 若要查看這些版本的檔,請將本文的 Visual Studio 版本 選取器控制項設定為 Visual Studio 2017 或更新版本。 其位於此頁面目錄頂端。

MatchEvent 式用來比對事件種類清單。 如果事件符合清單中的類型,則會轉送至處理常式以進行進一步處理。

語法

template <
    typename        TEvent,
    typename...     TEvents,
    typename        TCallable,
    typename...     TExtraArgs>
bool MatchEvent(
    const RawEvent& event,
    TCallable&&     callable,
    TExtraArgs&&... extraArgs);

參數

TEvent
您想要比對的第一個事件種類。

TEvents
您想要比對的其餘事件種類。

TCallable
支援 operator() 的類型。 如需哪些引數傳遞至此運算子的詳細資訊,請參閱 呼叫的參數描述。

TExtraArgs
傳遞至 MatchEvent 的額外引數類型。

event
要與 TEvent 和 TEvents 描述的事件種類相符的事件

調用
MatchEvent成功比對事件與 TEvent 和 TEvents 描述的任何事件種類之後,會叫用可 呼叫。 傳遞至 呼叫的第一個引數是相符事件種類的 r 值。 extraArgs 參數套件會在可 呼叫的 其餘參數中完美轉送。

extraArgs
取得完美轉送給 呼叫的引數,以及相符的事件種類。

傳回值

bool如果比對成功,則 false 為 , true 否則為 。

備註

從擷取類別 清單中選取要用於 TEvent TEvents 參數的事件 類型。 如需事件清單和可用來比對的事件擷取類別,請參閱 事件資料表

範例

void MyClass::OnStartActivity(const EventStack& eventStack)
{
    // Let's assume eventStack contains:
    // [Compiler, BackEndPass, C2DLL, CodeGeneration, Thread, Function]

    auto& functionEvent = eventStack.Back(); // The Function event

    bool b1 = MatchEvent<Function, Thread>(
        functionEvent, [](auto matchedEvent){ /* Do something... */});

    bool b2 = MatchEvent<CodeGeneration, Thread>(
        functionEvent, [](auto matchedEvent){ /* Do something... */});


    // b1: true because the list of types contains Function, which is
    //     the type of the event we are trying to match.
    // b2: false because the list of types doesn't contain Function.
}