fre*_*low 36 c++ typedef type-conversion coercion safe-bool-idiom
请考虑安全bool习语的以下摘录:
typedef void (Testable::*bool_type)() const;
operator bool_type() const;
Run Code Online (Sandbox Code Playgroud)
是否可以在没有typedef的情况下声明转换函数?以下内容无法编译:
operator (void (Testable::*)() const)() const;
Run Code Online (Sandbox Code Playgroud)
啊,我只记得identity元功能.可以写
operator typename identity<void (Testable::*)() const>::type() const;
Run Code Online (Sandbox Code Playgroud)
具有以下定义identity:
template <typename T>
struct identity
{
typedef T type;
};
Run Code Online (Sandbox Code Playgroud)
你可以说identity仍然使用a typedef,但这个解决方案对我来说足够"好".
| 归档时间: |
|
| 查看次数: |
919 次 |
| 最近记录: |