C++ Build Insights SDK 與 Visual Studio 2017 和更新版本相容。 若要查看這些版本的文件,請將本文的 Visual Studio 版本選取器控制項設定為 Visual Studio 2017 或更新版本。 其位於此頁面目錄頂端。
用於將事件堆疊與特定事件階層比對的 MatchEventStack 函式。 相符的階層會轉送至處理程式以進行進一步處理。 若要深入瞭解事件、事件堆疊和階層,請參閱 事件數據表。
語法
template <
typename TEvent,
typename... TEvents,
typename TCallable,
typename... TExtraArgs>
bool MatchEventStack(
const EventStack& eventStack,
TCallable&& callable,
TExtraArgs&&... extraArgs);
參數
TEvent
要比對事件堆疊中最長父代的類型。
TEvents
您想要在事件堆疊中比對的其餘類型。
TCallable
支援 operator()的類型。 如需有關傳遞至此運算子的參數詳細資訊,請參閱 可呼叫 參數的描述。
TExtraArgs
傳遞至 MatchEventStack的額外自變數類型。
eventStack
要與 TEvent 和 TEvents 所描述的事件類型階層相匹配的事件堆疊。
可調用
當成功比對事件堆疊與由 TEvent 和 TEvents 所描述的事件類型階層時,MatchEventStack會調用callable。 它會傳遞至 事件階層中每個類型可 呼叫的一個 r 值自變數。
extraArgs 參數套件會在 調用目標 的其餘參數中完美轉發。
extraArgs
取得完美轉遞給可呼叫物件的參數,以及匹配的事件類型。
傳回值
bool如果比對成功,則true為 ,false否則為 。
備註
在 eventStack 中的最後一個事件,始終會與串接的 [TEvent, TEvents...] 類型列表中的最後一個條目進行匹配。 所有其他 TEvent 和 TEvents 條目可以匹配 eventStack 中的任何位置,但不能是最後一個,前提是它們的順序一致。
從擷取類別清單中選取要用於 TEvent 和 TEvents 參數的事件類型。 如需事件清單和可用來比對的事件擷取類別,請參閱 事件數據表。
範例
void MyClass::OnStartActivity(const EventStack& eventStack)
{
// Let's assume eventStack contains:
// [Compiler, BackEndPass, C2DLL, CodeGeneration, Thread, Function]
bool b1 = MatchEventStack<Compiler, BackEndPass, C2DLL,
CodeGeneration, Thread, Function>(
eventStack, [](Compiler cl, BackEndPass bep, C2DLL c2,
CodeGeneration cg, Thread t, Function f){ /* Do something ... */ });
bool b2 = MatchEventStack<Compiler, Function>(
eventStack, [](Compiler cl, Function f){ /* Do something... */ });
bool b3 = MatchEventStack<Thread, Compiler, Function>(
eventStack, [](Thread t, Compiler cl Function f){ /* Do something... */ });
bool b4 = MatchEventStack<Compiler>(
eventStack, [](Compiler cl){ /* Do something... */ });
// b1: true because the list of types matches the eventStack exactly.
// b2: true because Function is the last entry in both the type list
// and 'eventStack', and also because Compiler comes before
// Function in 'eventStack' and in the type list.
// b3: false because, even though both Thread and Compiler come
// before Function in 'eventStack', they aren't listed in the
// right order in the type list.
// b4: false because the last entry in the type list is Compiler,
// which doesn't match the last entry in 'eventStack' (Function).
}