Nested C++ template parameters for functions

后端 未结 3 1364
再見小時候
再見小時候 2020-12-13 09:20

I want to have a templated function in C++, where one template parameter is itself a template of another template parameter. If that doesn\'t make any sense, take the follow

3条回答
  •  轮回少年
    2020-12-13 10:10

    std::vector has two parameters, type and allocator. Try this

    template  class V>
    void print_container(V &con)
    {
    }
    
    print_container(vec);
    

    This will work for vector, list, etc., but will not work with map, set.

    However, since you use auto you can use C++11 and then you can to this:

    template  class V, typename... Args>
    void print_container(V &con)
    

    or

    template