Basics of Conditional Instantiation - 2025.1 English - XD100

Vitis Tutorials: AI Engine Development (XD100)

Document ID
XD100
Release Date
2025-08-25
Version
2025.1 English

conditional is a C++ feature belonging to the standard library. The format is:

typename std::conditional< BOOLEAN_CONDITION , TYPE_IF_TRUE , TYPE_IF_FALSE >::type VARIABLE;

If BOOLEAN_CONDITION is True, then VARIABLE is generated with type TYPE_IF_TRUE. If the condition is False, VARIABLE is also generated but with type TYPE_IF_FALSE.

For aiecompiler environment, the BOOLEAN_CONDITION will be generally passed through template parameter. Though VARIABLE is always created, the type is different depending on the condition. In the examples provided, TYPE_IF_TRUE is the port type, graph class name that is of interest, and TYPE_IF_FALSE is a dummy type like int or std::tuple<>.