If you have some performance-critical part of the code, you can help the compiler to optimize the code with [[likely]] and [[unlikely]] attributes.

auto f(int i) -> int
{
    switch (i)
    {
        case 1: [[fallthrough]];
        [[likely]] case 2: return 1;
    }
    return 2;
}

https://en.cppreference.com/w/cpp/language/attributes/likely

Next - Previous