αλεχολυτ
αλεχολυτ

Reputation: 5039

User-defined deduction guide for std types

For some reason there is still lack of expected CTAD for std::initializer_list in clang:

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?

Upvotes: 4

Views: 152

Answers (1)

Oliv
Oliv

Reputation: 18081

Adding a deduction guide to a standard library type is 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.

Upvotes: 5

Related Questions