0
点赞
收藏
分享

微信扫一扫

d函数属性最佳实践


原文​​'const'​​除外,它不是​​臭味​​,因为某些模板是成员函数.并且成员函数上的​​"const"​​不能留给​​推导​​,因为它恰好是​​函数​​可​​重载​​类型的一部分.
需要创建显示​​普通函数,成员函数及其模板上​​的每个函数属性的含义的​​二维表​​,并提出​​指导方针​​.
​const, inout, shared​​属性与​​@safe,@trusted​​不一样.

​属性​

​效果​

​推导​

​nothrow ​

Function

Yes

​pure ​

Function

Yes

​@nogc ​

Function

Yes

​@safe ​

Function

Yes

​@system ​

Function

Yes

​@trusted ​

Function

No

​@property​

Function

No

​@disable ​

Function

No

​const ​

this

No

​immutable​

this

No

​inout ​

this

No

​shared ​

this

No

​return ​

this

Yes

​scope ​

this

Yes

"​​推导​​​"中带有"是"的属性的​​列​​​不应​​显式​​​应用于属性​​推导​​​的​​函数​​​.
包括在​​​模板​​​中定义的函数,以及​​嵌套​​​函数和具有​​推导​​​返回类型的函数(即​​auto​​函数).

将​​const​​​放入尽可能多的​​成员函数​​​中.该准则使​​函数​​​更有用,因为可以在​​可变,常和不变​​对象上调用它.


举报

相关推荐

0 条评论