175. Template

Question.11

A template function uses if constexpr for type-dependent behavior:

template<typename T>
void send(T val) {
   if constexpr (sizeof(T) == 1)
       uart_send_byte(val);
   else if constexpr (sizeof(T) <= 4)
       uart_send_word(val);
   else
       uart_send_block(&val, sizeof(T));
}

For send <uint8_t>(0x42), which branch exists in the binary?

Need Help? Refer to the Quick Guide below

Select Answer