c++ 使用一个使用成员类型别名的构造函数来引用类模板参数

栏目: C++ · 发布时间: 6年前

内容简介:代码日志版权声明:翻译自: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


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Designing Data-Intensive Applications

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》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具