Template template parameters and default arguments

后端 未结 2 682
灰色年华
灰色年华 2021-01-19 04:41

Consider the following code which uses \"template template\" parameters to instantiate a class template using multiple types:

#include 
using         


        
2条回答
  •  有刺的猬
    2021-01-19 05:10

    With a using template alias, a new feature in C++11, you can create a one-parameter template that is equivalent to another template that has two parameters, one of which is defaulted.

    template  using Foo1 = Foo;
    

    This creates Foo1, a one-parameter template, even though Foo technically has two arguments, one of which is defaulted. You can use it as:

    do_something(int(55));
    

    Alternatively, if C++11 features such as using are not available, then you scan specify the default in your declaration of do_something. This means then, unfortunately, that do_something can no longer deal with simple one-arg templates. Hence, I think the using method above is better.

    template