是否有标准的 Untokenize 模板类型?

j5w*_*j5w 2 c++ c++17

是否有一个标准类型来取消类型标记?它可能会这样实现:

template<class T>
using untokenize = T;
Run Code Online (Sandbox Code Playgroud)

这样我可以使用重载运算符执行以下转换:

struct x {
  int y;
  operator int&() {
    return y;
  }
};

x a;
// int&(a); // doesn't work
// (int&)(a); // not the same thing
untokenize<int&>(a); // works great
Run Code Online (Sandbox Code Playgroud)

或者是否有另一种更标准的方法来实现我的目标,即避免使用 c 风格转换而支持函数风格转换?

Joh*_*nck 9

static_cast<T>做你所要求的。