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會叫用可呼叫。 它會傳遞至 事件階層中每個類型可 呼叫的一個 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).
}