const_forward在C中的可选实现中做了什么?
嗨我在
here看到std :: optional实现之一,我发现这段代码让我感到困惑:
// workaround: std utility functions aren't constexpr yet template <class T> inline constexpr T&& constexpr_forward(typename std::remove_reference<T>::type& t) noexcept { return static_cast<T&&>(t); } 所以我不会通过以下方式理解这一点: > typename在这做什么?只是声明以下部分是一种类型? 非常感谢. 解决方法template <class T> inline constexpr T&& constexpr_forward(typename std::remove_reference<T>::type& t) noexcept { return static_cast<T&&>(t); }
std :: remove_reference< T> :: type是一个依赖类型,它取决于模板参数T,因此我们需要typename来告诉编译器我们正在尝试使用dependent-name,
如果您在here中检查此实用程序功能的示例用法 .... template <class... Args> explicit constexpr constexpr_optional_base(in_place_t,Args&&... args) : init_(true),storage_(constexpr_forward<Args>(args)...) {} ... 你可以看到,一个可变参考类型被用作constexpr_foward< Args>(args)的显式模板参数….这将保留该类型的value category.当任何参数是引用时,就好像我们使用constexpr_forward< Arg01&>(arg01)调用该实用程序函数一样.并且该模板的实例化将是 inline constexpr Arg01&&& constexpr_forward(Arg01& t) noexcept { return static_cast<Arg01&&&>(t); } 到了reference collapsing rule,我们有 inline constexpr Arg01& constexpr_forward(Arg01& t) noexcept { return static_cast<Arg01&>(t); } 实际上,删除引用应该是多余的(阅读参考折叠);
它只是forwarding constexpr函数和构造函数中的非constexpr函数.
基本上如上所述.. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- XML模式(XSD)验证工具?
- ruby-on-rails – Vue.JS和Rails-UJS / Jquery-UJS冲突 –
- ruby-on-rails – 保存主对象时,ActiveRecord是否保存belon
- 提高Ajax速度的几点方法
- ruby-on-rails-3 – Rails3 form_for hidden_??field未定义
- xml中用fragment出现Error inflating class fragment的问题
- ZeosLib 的使用 TZQuery实例
- 正则表达式 常用的正则表达式
- c# – NServiceBus升级2.5到3.2总是重新安装MSMQ,有没有办法
- dojo1.8 培训教材 新手老手适用 - 汇丰银行 [英文]