mercredi 11 octobre 2017

Questions about the definition of std::function class

I saw its source code is

template<class R, class... ArgTypes>                                                                                                            
class function<R(ArgTypes...)>
  : public unary_function<T1, R>      // iff sizeof...(ArgTypes) == 1 and
                                      // ArgTypes contains T1
  : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
                                      // ArgTypes contains T1 and T2
{...};

Here I have two questions for it:

  1. Is it legal to have

    class C : public A : public D {}

? It seems illegal but the source code for std::function does compile. Why?

  1. What does this

    template<class A, B> class foo<A(B)> //Can we have "<...>" here? What's its meaning? {...}

mean? As an old man who's only familiar with C++98 I don't understand class foo<A(B)>, and I thought a type parameter list <...> could only appear after the template for a template definition. BTW, I know A(B) can be a function type.

Aucun commentaire:

Enregistrer un commentaire