Variadic deduction guide not taken by g++, taken by clang++ – who is correct?

This is gcc bug 80871. The issue is, we end up with this set of candidates for deduction: template <class… Types, class… Args> list<Types…> __f(Args… ); // constructor template <class… Args> list<Args…> __f(Args… ); // deduction-guide Both are valid (Types… can deduce as empty in the first case), but the call here should be ambiguous … Read more

Why do auto and template type deduction differ for braced initializers?

There are two important reasons for templates not to do any deduction (the two that I remember in a discussion with the guy in charge) Concerns about future language extensions (there are multiple meanings you could invent – what about if we wanted to introduce perfect forwarding for braced init list function arguments?) The braces … Read more

Deduce template argument from std::function call signature

A function pointer of type bool (*)() can be converted to std::function<bool()> but is not the same type, so a conversion is needed. Before the compiler can check whether that conversion is possible it needs to deduce ReturnT as bool, but to do that it needs to already know that std::function<bool()> is a possible conversion, … Read more

What is the partial ordering procedure in template deduction

While Xeo gave a pretty good description in the comments, I will try to give a step-by-step explanation with a working example. First of all, the first sentence from the paragraph you quoted says: For each of the templates involved there is the original function type and the transformed function type. […] Hold on, what … Read more

What are template deduction guides and when should we use them?

Template deduction guides are patterns associated with a template class that tell the compiler how to translate a set of constructor arguments (and their types) into template parameters for the class. The simplest example is that of std::vector and its constructor that takes an iterator pair. template<typename Iterator> void func(Iterator first, Iterator last) { vector … Read more

What is a nondeduced context?

Deduction refers to the process of determining the type of a template parameter from a given argument. It applies to function templates, auto, and a few other cases (e.g. partial specialization). For example, consider: template <typename T> void f(std::vector<T>); Now if you say f(x), where you declared std::vector<int> x;, then T is deduced as int, … Read more

tech