Is it possible to avoid static_cast in initializer list?
问题 In my code base I often initialize array or vector if bytes using the following the syntax: uint16_t foo = 0xAB, bar = 0xCD // bytes = { 0xA, 0xB, 0xC, 0xD } std::array<uint8_t, 4> bytes = {{ foo >> 8, foo & 0x00FF, bar >> 8, bar & 0x00FF }}; I get the following error from clang++: error: non-constant-expression cannot be narrowed from type 'int' to 'value_type' (aka 'unsigned char') in initializer list [-Wc++11-narrowing] foo >> 8, ^~~~~~~~~~~~~ The compiler suggest me to add a static_cast