std::common_type implementation

前端 未结 3 839
清歌不尽
清歌不尽 2021-02-20 04:43

Just to see how it worked, I looked at the libstdc++ implementation of std::common_type in the header type_traits. I have to admit that I don\'t really

3条回答
  •  余生分开走
    2021-02-20 04:57

    The third version uses the conditional operator to determine the common type. Its rules are described at quite a length in section 5.16 of the standard, so I'm not sure I should copy them here.

    Simply put, the expression:

    boolean-expression ? second-operand : third-operand
    

    has a "common type" of the second and third operands, if such exists. The decltype specifier is then used to "convert" the expression into a type-specifier.

提交回复
热议问题