内容简介:代码日志版权声明:翻译自:http://stackoverflow.com/questions/43530295/deducing-class-template-arguments-with-a-constructor-that-uses-a-member-type-ali
显然这应该是有效的:
template<class T> struct C { using value_type = T; C(value_type); }; C c(1); // C<int>
就这样(见 [over.match.class.deduct]/3 中的B示例):
template<class T> struct D { template<class> using meow_t = T; template<class U> D(U, meow_t<U>); }; D d(1, 'c'); // D<char>
请注意,由于参数是未推断的上下文,因此看似相当的显式指南将不起作用:
template<class T> C(typename C<T>::value_type) -> C<T>;
尽管至少第一个代码片段的工作肯定是可取的,但我还没有找到实际上使其在当前工作草案中工作的措辞.有谁知道它在哪里?
这不是一个严格的答案,因为我不认为这样的措辞实际上是存在的.这更多的是与这个问题相关的信息.
这是 Core Issue 2 .在Oulu和Issaquah关于这个功能的讨论清楚地表明,目的是通过typedefs查看是有效的,但是没有添加任何措辞来表明这是如何运作的 – 它只是… .这个措辞表明,扣除指南为:
template<class T> struct C { using value_type = T; C(value_type); };
将会:
template <class T> C<T> foo(typename C<T>::value_type );
这将是一个未被推断的情况并失败,但 [thread.lock.guard] 没有明确的扣除指南.
[over.match.best] 中的示例显然是为了表明typedefs应该可以工作,尽管该示例中的示例实际上不使用#1作为扣除指南:
06002
代码日志版权声明:
翻译自:http://stackoverflow.com/questions/43530295/deducing-class-template-arguments-with-a-constructor-that-uses-a-member-type-ali
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- Git命令别名设置
- mybatis的typeAliases别名
- Elasticsearch基础但非常有用的功能之一:别名
- Elasticsearch索引的基本操作(5)-别名设置
- Elasticsearch 技术分析(三): 索引别名Aliases问题
- c++ 这是否真的破坏了严格的别名规则?
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Designing Data-Intensive Applications
Martin Kleppmann / O'Reilly Media / 2017-4-2 / USD 44.99
Data is at the center of many challenges in system design today. Difficult issues need to be figured out, such as scalability, consistency, reliability, efficiency, and maintainability. In addition, w......一起来看看 《Designing Data-Intensive Applications》 这本书的介绍吧!