std::common_type implementation

前端 未结 3 787
清歌不尽
清歌不尽 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 05:02

    Long Story Short: The decltype is making the C++ compiler determine the closest ancestor type for it.

    Tertiary Operator's have the resulting static type of the closest ancestor of the two possible expressions.

    E.g:

    A inherits from B

    X inherits from Y inherits from B

     ?  :  
        =   // this is how the C++ parser sees it
    

    This is how the C++ language works. The decltype just makes the typedef be the static type of the result of that expression (whatever type the C++ compiler determines it to be)

提交回复
热议问题