gpt4 book ai didi

c++ - std::result_of 用于内置运算符

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:16:07 33 4
gpt4 key购买 nike

通过 result_of 确定诸如 -int()double()*double() 之类的结果的正确语法是什么?

失败

std::result_of<operator-(int)>::type
std::result_of<operator*(double,double)>::type

最佳答案

std::result_of真的不是这里采取的方法。 decltype做你想做的,可以用作 decltype(-int()) , decltype(double()*double())等等 如果你不知道类型是否是默认构造的,你也可以使用 std::declval : decltype(-std::declval<int>()) .

任何语法涉及 operator- 的原因不会工作是因为 operator-语法仅适用于自定义重载运算符。内置算子没有任何可以引用的支持函数。

关于c++ - std::result_of 用于内置运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27511100/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com