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的額外自變數類型。
事件
要與 TEvent 和 TEvents 所描述的事件類型相符的事件。
調用
MatchEvent
成功比對事件與 TEvent 和 TEvents 所描述的任何事件類型之後,會叫用可呼叫。 傳遞至 可 呼叫的第一個自變數是相符事件類型的 r 值。
extraArgs 參數套件會在可呼叫的其餘參數中完美轉送。
extraArgs
取得完美轉送給 可 呼叫的自變數,以及相符的事件類型。
傳回值
bool如果比對成功,則true為 ,false否則為 。
備註
從擷取類別清單中選取要用於 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.
}