Questions about deriving template template argument in C ++ 17

I am trying to understand P0091r3 (the document "template argument for class templates" that has been adopted in the current standard C ++ project, N4606).

I believe that I understand how this works in the simplest case when a template name identifies one template:

template<class T>
struct S {
    S(T);
    S(const std::vector<T>&);
};

int main()
{
    std::vector<int> v;
    auto s = S(v);
}

S identifies the primary template, so we create a dummy overload set consisting of

template<class T> void Sctor(T);
template<class T> void Sctor(const std::vector<T>&);

and perform overload resolution on a fake call

Sctor(v)

to determine what in this case we want to call fictitious Sctor(const std::vector<T>&) [with T=int]. This means that we end up calling S<int>::S(const std::vector<int>&), and everything works just fine.

I do not understand how this should work in the presence of partial specialization.

template<class T>
struct S {
    S(T);
};

template<class T>
struct S<std::list<T>> {
    S(const std::vector<T>&);
};

int main()
{
    std::vector<int> v;
    auto s = S(v);
}

, , S<std::list<int>>::S(const std::vector<int>&). , ? ?

, P0091r3 " , ": ?

( , P0091r3 §7.1.6.2p2, ,

template<class T>
struct iterator {
    iterator& operator++(int) {
        iterator result = *this;  // injected-class-name or placeholder?
        //...
    }
};

.)


Clang GCC (, -f, -fconcepts)? , , , .

+4
2

, , , . , [class.template.deduction] :

  • , , - : [...]

"the", , , ([temp.class.spec]/6). , (. ).

" ", - , (-SFINAE) :/p >

template<class T> struct X {
   using ty = T::type;
   static auto foo() { return typename T::type{} };
   X(ty); #1
   X(decltype(foo())); #2
   X(T);
};
template<class T>
struct X<T*> { 
   X(...);
};
X x{(int *)0};

, , :

template<class T> struct Y { Y(T*); };
template<class T> struct Y<T*> { Y(T*); };
Y y{(int*) 0};

, , ( -) .

, clang github: https://github.com/faisalv/clang/tree/clang-ctor-deduction.


( " " ) , ; ​​:

, .

+2

, P0091, , . , .

, , P0091 , . , . , , - . S<std::list<T>> - std::list S.

, , . , , .

+1

Source: https://habr.com/ru/post/1653881/


All Articles