c++ - 是否有标准的 Untokenize 模板化类型?

标签 c++ c++17

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

template<class T>
using untokenize = T;

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

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

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

最佳答案

static_cast<T>做你要求的。

关于c++ - 是否有标准的 Untokenize 模板化类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70408591/

相关文章:

c++ - 乘以0优化

c++ - 2种模板类型之间的转换

c++ - 为什么 pair 在初始化时不需要类型

c++ - 项目错误 : Unknown module(s) in QT: script?

c++ - 在 Visual Studio 2013 和 Visual Studio 2012 之间共享项目

C++:将 void* 转换为基类指针时发生访问冲突

c++ - std::map 的复制列表初始化,其中 std::variant 作为mapped_type

c++ - 链接不同C++标准编译的库有没有隐患?

c++ - 如何使用 C++ 17 检查 operator != 是否存在模板参数?

c++ - 具有先前模板参数类型的自动返回类型参数的函数类型的模板参数