Are there cases where a typedef is absolutely necessary?

后端 未结 8 1153
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 01:21

Consider the following excerpt from the safe bool idiom:

typedef void (Testable::*bool_type)() const;
operator bool_type() const;

Is it possibl

8条回答
  •  情书的邮戳
    2021-02-05 02:11

    Ah, I just remembered the identity meta-function. It is possible to write

    operator typename identity::type() const;
    

    with the following definition of identity:

    template 
    struct identity
    {
        typedef T type;
    };
    

    You could argue that identity still uses a typedef, but this solution is "good" enough for me.

提交回复
热议问题