简体   繁体   English

用户定义的标准类型推导指南

[英]User-defined deduction guide for std types

For some reason there is still lack of expected CTAD for std::initializer_list in clang :由于某种原因, clang中的std::initializer_list仍然缺少预期的CTAD

std::initializer_list l{1,2,3}; // error in clang

Adding a user-defined guide like the following can fix the issue :添加如下用户定义的指南可以解决此问题

namespace std {
    template<class T> 
    initializer_list(const initializer_list<T>&) -> initializer_list<T>; 
} 

But is it allowed to add a user-defined guide for CTAD for std:: types?但是是否允许为std::类型添加 CTAD 的用户定义指南?

Adding a deduction guide to a standard library type is UB [namespace std]§4.4 :为标准库类型添加推导指南是 UB [namespace std]§4.4

The behavior of a C++ program is undefined if it declares: [...]如果 C++ 程序声明: [...]

  • a deduction guide for any standard library class template.任何标准库 class 模板的演绎指南。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM