int(int)&是什么类型或int(int)const&amp ;? [英] What type is int(int)& or int(int) const &?

查看:109
本文介绍了int(int)&是什么类型或int(int)const&amp ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

std :: is_function 专用于签名类似于以下类型的类型:

std::is_function is specialized for types which have signature similar to:

int(int) &

请参见此处: std :: is_function

但这不是指向成员方法的指针,该成员方法可以是:

But this is neither a pointer to a member method, which signature could be:

int(T::*)(int) &

也可以是对函数的引用:

Nor it can be a reference to a function:

int (&)(int)

那么,这个奇怪的签名是什么?

So what is this strange signature?

推荐答案

这是一个仅在类型系统中存在的函数类型。

It's a function type which only exists in the type system. It cannot ever be created.


但这不是指向成员方法的指针,该成员方法可以是:

But this is neither a pointer to a member method, which signature could be:

int(T::*)(int) &


就是这个,没有指针。类型系统允许您将其描述为类型。

It's this, without the pointer. The type system allows you to describe that as a type.

#include <type_traits>

struct T { };
using A = int(int) &;
using B = A T::*;
using C = int(T::*)(int) &;

static_assert(std::is_same_v<B, C>);

@ T.C。提到 PR0172R0 ,其中讨论了这些类型的存在会给图书馆编写者带来麻烦,并提出了可能减少这些问题的几种选择。一种选择是完全摆脱它们,其他选择则减少其影响。根据具体情况,此答案对于将来的C ++版本可能正确,也可能不正确。

@T.C. mentions PR0172R0, which discusses how the presence of these types causes issues for library writers, and suggests several options which might reduce those issues. One of the options is getting rid of them entirely, others reduce their impact. Depending on how this goes, this answer may or may not be correct for future versions of C++.

这篇关于int(int)&amp;是什么类型或int(int)const&amp ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆