c++ - 用户定义的 std 类型推导指南

标签 c++ language-lawyer clang++ ctad

出于某种原因,仍然缺乏预期的CTADstd::initializer_listclang :

std::initializer_list l{1,2,3}; // error in clang
添加如下所示的用户定义指南可以 fix the issue :
namespace std {
    template<class T> 
    initializer_list(const initializer_list<T>&) -> initializer_list<T>; 
} 
但是是否允许为 std:: 添加用户定义的 CTAD 指南?类型?

最佳答案

向标准库类型添加推导指南是 UB [namespace std]§4.4 :

The behavior of a C++ program is undefined if it declares : [...]


  • a deduction guide for any standard library class template.

关于c++ - 用户定义的 std 类型推导指南,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63424573/

相关文章:

c++ - 使用 reinterpret_cast 将函数强制转换为 void*,为什么不违法?

c++ - 尽管有更新,clang 还是产生了关于 c++11 的警告

c++ - 我真的需要为 const 对象实现用户提供的构造函数吗?

c++ - Friend 模板函数类内定义

c++ - 在 C++、Ubuntu 中使用 BMP 文件

c++ - 可以安全地依赖 unordered_map(hashmap)中的初始化值

c++ - 如何强制编译器将非零值设置为未初始化的变量?

c++ - Clang 看不到基本标题

c++ - 初始化表达式可以使用变量本身吗?

c++ - __purecall 在 VS2010 中使用虚函数的问题 - 一旦方法获得 purecall